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"
27 #include "wx/combobox.h"
28 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr
[] = "comboBox";
36 #include "wx/dcclient.h"
37 #include "wx/settings.h"
39 #include "wx/textctrl.h"
42 #include "wx/tooltip.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxDEFINE_FLAGS( wxComboBoxStyle
)
52 wxBEGIN_FLAGS( wxComboBoxStyle
)
53 // new style border flags, we put them first to
54 // use them for streaming out
55 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
56 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
57 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
58 wxFLAGS_MEMBER(wxBORDER_RAISED
)
59 wxFLAGS_MEMBER(wxBORDER_STATIC
)
60 wxFLAGS_MEMBER(wxBORDER_NONE
)
62 // old style border flags
63 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
64 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
65 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
66 wxFLAGS_MEMBER(wxRAISED_BORDER
)
67 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
68 wxFLAGS_MEMBER(wxBORDER
)
70 // standard window styles
71 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
72 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
73 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
74 wxFLAGS_MEMBER(wxWANTS_CHARS
)
75 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
76 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
77 wxFLAGS_MEMBER(wxVSCROLL
)
78 wxFLAGS_MEMBER(wxHSCROLL
)
80 wxFLAGS_MEMBER(wxCB_SIMPLE
)
81 wxFLAGS_MEMBER(wxCB_SORT
)
82 wxFLAGS_MEMBER(wxCB_READONLY
)
83 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
85 wxEND_FLAGS( wxComboBoxStyle
)
87 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
89 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
90 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
)
91 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
94 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
95 0 /*flags*/, wxT("Helpstring"), wxT("group"))
96 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
97 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
98 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
99 0 /*flags*/, wxT("Helpstring"), wxT("group"))
100 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
101 0 /*flags*/, wxT("Helpstring"), wxT("group"))
103 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
104 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
105 wxT("Helpstring"), wxT("group")) // style
106 wxEND_PROPERTIES_TABLE()
108 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
110 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
111 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
114 // ----------------------------------------------------------------------------
116 #define DEFAULT_DROPBUTTON_WIDTH 19
118 #define BMP_BUTTON_MARGIN 4
120 #define DEFAULT_POPUP_HEIGHT 400
122 #define DEFAULT_TEXT_INDENT 3
124 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
127 #if defined(__WXMSW__)
129 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
130 #include "wx/frame.h"
131 #define wxCC_GENERIC_TLW_IS_FRAME
132 #define wxComboCtrlGenericTLW wxFrame
134 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
135 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
136 // native controls work on it like normal.
137 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
138 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
139 #define FOCUS_RING 0 // No focus ring on wxMSW
141 //#undef wxUSE_POPUPWIN
142 //#define wxUSE_POPUPWIN 0
144 #elif defined(__WXGTK__)
146 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
147 // this bug: If wxDialog is hidden, its position becomes corrupt
148 // between hide and next show, but without internal coordinates being
149 // reflected (or something like that - atleast commenting out ->Hide()
150 // seemed to eliminate the position change).
152 #include "wx/dialog.h"
153 #define wxCC_GENERIC_TLW_IS_DIALOG
154 #define wxComboCtrlGenericTLW wxDialog
156 #if defined(__WXGTK20__)
157 # include "wx/gtk/private.h"
159 # include "wx/gtk1/private.h"
162 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
163 // 'perfect' popup, as it can successfully host child controls even in
164 // popups that are shown in modal dialogs.
166 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
167 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
168 // native controls work on it like normal.
169 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
170 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
171 #define FOCUS_RING 0 // No focus ring on wxGTK
173 #elif defined(__WXMAC__)
175 #include "wx/nonownedwnd.h"
176 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
177 #define wxComboCtrlGenericTLW wxNonOwnedWindow
179 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
180 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
181 // native controls work on it like normal.
182 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
183 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
184 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
186 #undef DEFAULT_DROPBUTTON_WIDTH
187 #define DEFAULT_DROPBUTTON_WIDTH 22
189 #define COMBO_MARGIN FOCUS_RING
193 #include "wx/dialog.h"
194 #define wxCC_GENERIC_TLW_IS_DIALOG
195 #define wxComboCtrlGenericTLW wxDialog
197 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
198 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
199 // native controls work on it like normal.
200 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
201 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
207 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
208 // what the wxUSE_POPUPWIN says.
209 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
210 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
211 #undef wxUSE_POPUPWIN
212 #define wxUSE_POPUPWIN 0
217 #include "wx/popupwin.h"
219 #undef USE_TRANSIENT_POPUP
220 #define USE_TRANSIENT_POPUP 0
224 // Define different types of popup windows
228 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
229 POPUPWIN_WXPOPUPWINDOW
= 2,
230 POPUPWIN_GENERICTLW
= 3
234 #if USE_TRANSIENT_POPUP
235 // wxPopupTransientWindow is implemented
237 #define wxComboPopupWindowBase wxPopupTransientWindow
238 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
239 #define USES_WXPOPUPTRANSIENTWINDOW 1
241 #if TRANSIENT_POPUPWIN_IS_PERFECT
243 #elif POPUPWIN_IS_PERFECT
244 #define wxComboPopupWindowBase2 wxPopupWindow
245 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
246 #define USES_WXPOPUPWINDOW 1
248 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
249 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
250 #define USES_GENERICTLW 1
254 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
256 #define wxComboPopupWindowBase wxPopupWindow
257 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
258 #define USES_WXPOPUPWINDOW 1
260 #if !POPUPWIN_IS_PERFECT
261 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
262 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
263 #define USES_GENERICTLW 1
267 // wxPopupWindow is not implemented
269 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
270 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
271 #define USES_GENERICTLW 1
276 #ifndef USES_WXPOPUPTRANSIENTWINDOW
277 #define USES_WXPOPUPTRANSIENTWINDOW 0
280 #ifndef USES_WXPOPUPWINDOW
281 #define USES_WXPOPUPWINDOW 0
284 #ifndef USES_GENERICTLW
285 #define USES_GENERICTLW 0
289 #if USES_WXPOPUPWINDOW
290 #define INSTALL_TOPLEV_HANDLER 1
292 #define INSTALL_TOPLEV_HANDLER 0
296 // Returns true if given popup window type can be classified as perfect
298 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
300 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
301 wxUnusedVar(popupWinType
);
304 return ( popupWinType
== POPUPWIN_GENERICTLW
305 #if POPUPWIN_IS_PERFECT
306 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
308 #if TRANSIENT_POPUPWIN_IS_PERFECT
309 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
318 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
322 // ----------------------------------------------------------------------------
323 // wxComboFrameEventHandler takes care of hiding the popup when events happen
324 // in its top level parent.
325 // ----------------------------------------------------------------------------
327 #if INSTALL_TOPLEV_HANDLER
330 // This will no longer be necessary after wxTransientPopupWindow
331 // works well on all platforms.
334 class wxComboFrameEventHandler
: public wxEvtHandler
337 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
338 virtual ~wxComboFrameEventHandler();
342 void OnIdle( wxIdleEvent
& event
);
343 void OnMouseEvent( wxMouseEvent
& event
);
344 void OnActivate( wxActivateEvent
& event
);
345 void OnResize( wxSizeEvent
& event
);
346 void OnMove( wxMoveEvent
& event
);
347 void OnMenuEvent( wxMenuEvent
& event
);
348 void OnClose( wxCloseEvent
& event
);
351 wxWindow
* m_focusStart
;
352 wxComboCtrlBase
* m_combo
;
355 DECLARE_EVENT_TABLE()
358 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
359 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
360 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
361 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
362 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
363 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
364 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
365 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
366 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
367 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
370 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
376 wxComboFrameEventHandler::~wxComboFrameEventHandler()
380 void wxComboFrameEventHandler::OnPopup()
382 m_focusStart
= ::wxWindow::FindFocus();
385 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
387 wxWindow
* winFocused
= ::wxWindow::FindFocus();
389 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
390 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
393 winFocused
!= m_focusStart
&&
394 winFocused
!= popup
&&
395 winFocused
->GetParent() != popup
&&
396 winFocused
!= winpopup
&&
397 winFocused
->GetParent() != winpopup
&&
398 winFocused
!= m_combo
&&
399 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
402 m_combo
->HidePopup(true);
408 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
410 m_combo
->HidePopup(true);
414 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
416 m_combo
->HidePopup(true);
420 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
422 m_combo
->HidePopup(true);
426 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
428 m_combo
->HidePopup(true);
432 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
434 m_combo
->HidePopup(true);
438 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
440 m_combo
->HidePopup(true);
444 #endif // INSTALL_TOPLEV_HANDLER
446 // ----------------------------------------------------------------------------
447 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
449 // ----------------------------------------------------------------------------
451 class wxComboPopupWindow
: public wxComboPopupWindowBase
455 wxComboPopupWindow( wxComboCtrlBase
*parent
,
457 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
458 : wxComboPopupWindowBase(parent
,style
)
460 : wxComboPopupWindowBase(parent
,
471 #if USES_WXPOPUPTRANSIENTWINDOW
472 virtual bool Show( bool show
);
473 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
475 virtual void OnDismiss();
483 #if USES_WXPOPUPTRANSIENTWINDOW
484 bool wxComboPopupWindow::Show( bool show
)
486 // Guard against recursion
488 return wxComboPopupWindowBase::Show(show
);
492 wxPopupTransientWindow
* const
493 ptw
= static_cast<wxPopupTransientWindow
*>(this);
495 if ( show
!= ptw
->IsShown() )
498 // We used to do wxPopupTransientWindow::Popup here,
499 // but this would hide normal Show, which we are
500 // also going to need.
511 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
513 return wxPopupTransientWindow::ProcessLeftDown(event
);
516 // First thing that happens when a transient popup closes is that this method gets called.
517 void wxComboPopupWindow::OnDismiss()
519 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
520 wxASSERT_MSG( wxDynamicCast(combo
, wxComboCtrlBase
),
521 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
523 combo
->OnPopupDismiss(true);
525 #endif // USES_WXPOPUPTRANSIENTWINDOW
528 // ----------------------------------------------------------------------------
529 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
530 // of a popup window. It is separate so we can have different types
532 // ----------------------------------------------------------------------------
534 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
538 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
543 void OnSizeEvent( wxSizeEvent
& event
);
544 void OnKeyEvent(wxKeyEvent
& event
);
546 void OnActivate( wxActivateEvent
& event
);
550 wxComboCtrlBase
* m_combo
;
552 DECLARE_EVENT_TABLE()
556 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
557 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
558 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
559 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
561 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
563 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
567 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
569 // Block the event so that the popup control does not get auto-resized.
572 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
574 // Relay keyboard event to the main child controls
575 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
576 wxWindowList::iterator node
= children
.begin();
577 wxWindow
* child
= (wxWindow
*)*node
;
578 child
->GetEventHandler()->ProcessEvent(event
);
582 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
584 if ( !event
.GetActive() )
586 // Tell combo control that we are dismissed.
587 m_combo
->HidePopup(true);
595 // ----------------------------------------------------------------------------
598 // ----------------------------------------------------------------------------
600 wxComboPopup::~wxComboPopup()
604 void wxComboPopup::OnPopup()
608 void wxComboPopup::OnDismiss()
612 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
614 return wxStaticCast(m_combo
, wxComboCtrl
);
617 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
619 int WXUNUSED(maxHeight
) )
621 return wxSize(minWidth
,prefHeight
);
624 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
625 wxDC
& dc
, const wxRect
& rect
)
627 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
629 combo
->PrepareBackground(dc
,rect
,0);
631 dc
.DrawText( combo
->GetValue(),
632 rect
.x
+ combo
->m_marginLeft
,
633 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
637 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
639 DefaultPaintComboControl(m_combo
,dc
,rect
);
642 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
647 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
652 void wxComboPopup::OnComboDoubleClick()
656 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
660 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
661 wxString
* WXUNUSED(trueItem
))
666 bool wxComboPopup::LazyCreate()
671 void wxComboPopup::Dismiss()
673 m_combo
->HidePopup(true);
676 void wxComboPopup::DestroyPopup()
678 // Here we make sure that the popup control's Destroy() gets called.
679 // This is necessary for the wxPersistentWindow to work properly.
680 wxWindow
* popupCtrl
= GetControl();
683 // While all wxComboCtrl examples have m_popupInterface and
684 // popupCtrl as the same class (that will be deleted via the
685 // Destroy() call below), it is technically still possible to
686 // have implementations where they are in fact not same
687 // multiple-inherited class. Here we use C++ RTTI to check for
690 // It is probably better to delete m_popupInterface first, so
691 // that it retains access to its popup control window.
692 if ( dynamic_cast<void*>(this) !=
693 dynamic_cast<void*>(popupCtrl
) )
696 popupCtrl
->Destroy();
704 // ----------------------------------------------------------------------------
706 // ----------------------------------------------------------------------------
709 // This is pushed to the event handler queue of the child textctrl.
711 class wxComboBoxExtraInputHandler
: public wxEvtHandler
715 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
720 virtual ~wxComboBoxExtraInputHandler() { }
721 void OnKey(wxKeyEvent
& event
);
722 void OnFocus(wxFocusEvent
& event
);
725 wxComboCtrlBase
* m_combo
;
728 DECLARE_EVENT_TABLE()
732 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
733 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
734 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
735 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
736 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
737 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
741 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
743 // Let the wxComboCtrl event handler have a go first.
744 wxComboCtrlBase
* combo
= m_combo
;
746 wxKeyEvent
redirectedEvent(event
);
747 redirectedEvent
.SetId(combo
->GetId());
748 redirectedEvent
.SetEventObject(combo
);
750 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
752 // Don't let TAB through to the text ctrl - looks ugly
753 if ( event
.GetKeyCode() != WXK_TAB
)
758 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
760 // FIXME: This code does run when control is clicked,
761 // yet on Windows it doesn't select all the text.
762 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
763 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
765 if ( m_combo
->GetTextCtrl() )
766 m_combo
->GetTextCtrl()->SelectAll();
768 m_combo
->SetSelection(-1,-1);
771 // Send focus indication to parent.
772 // NB: This is needed for cases where the textctrl gets focus
773 // instead of its parent. While this may trigger multiple
774 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
775 // from combo's focus event handler), they should be quite
777 wxFocusEvent
evt2(event
);
778 evt2
.SetId(m_combo
->GetId());
779 evt2
.SetEventObject(m_combo
);
780 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
787 // This is pushed to the event handler queue of the control in popup.
790 class wxComboPopupEvtHandler
: public wxEvtHandler
794 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
798 m_beenInside
= false;
800 // Let's make it so that the popup control will not receive mouse
801 // events until mouse left button has been up.
802 m_blockEventsToPopup
= true;
804 virtual ~wxComboPopupEvtHandler() { }
806 void OnMouseEvent( wxMouseEvent
& event
);
808 // Called from wxComboCtrlBase::OnPopupDismiss
809 void OnPopupDismiss()
811 m_beenInside
= false;
812 m_blockEventsToPopup
= true;
816 wxComboCtrlBase
* m_combo
;
819 bool m_blockEventsToPopup
;
822 DECLARE_EVENT_TABLE()
826 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
827 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
831 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
833 wxPoint pt
= event
.GetPosition();
834 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
835 int evtType
= event
.GetEventType();
836 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
837 bool relayToButton
= false;
841 if ( !isInside
|| !m_combo
->IsPopupShown() )
843 // Mouse is outside the popup or popup is not actually shown (yet)
845 if ( evtType
== wxEVT_MOTION
||
846 evtType
== wxEVT_LEFT_DOWN
||
847 evtType
== wxEVT_LEFT_UP
||
848 evtType
== wxEVT_RIGHT_DOWN
)
850 // Block motion and click events outside the popup
856 // Mouse is inside the popup, which is fully shown
860 // Do not let the popup control respond to mouse events until
861 // mouse press used to display the popup has been lifted. This
862 // is important for users with slower mouse fingers or mouse
863 // drivers. Note that we have some redundancy here, just in
864 // case the popup is some native control that does not emit all
865 // mouse event types.
866 if ( evtType
== wxEVT_MOTION
)
868 if ( m_blockEventsToPopup
)
870 if ( event
.LeftIsDown() )
873 m_blockEventsToPopup
= false;
876 else if ( evtType
== wxEVT_LEFT_DOWN
)
878 if ( m_blockEventsToPopup
)
879 m_blockEventsToPopup
= false;
881 else if ( evtType
== wxEVT_LEFT_UP
)
883 if ( m_blockEventsToPopup
)
885 // On first left up, stop blocking mouse events (but still
887 m_blockEventsToPopup
= false;
890 // Also, this button press was (probably) used to display
891 // the popup, so relay it back to the drop-down button
892 // (which supposedly originated it). This is necessary to
893 // refresh it properly.
894 relayToButton
= true;
897 else if ( m_blockEventsToPopup
)
904 // Some mouse events to popup that happen outside it, before cursor
905 // has been inside the popup, need to be ignored by it but relayed to
908 if ( evtType
== wxEVT_LEFT_UP
)
910 if ( !m_combo
->IsPopupShown() )
913 relayToButton
= true;
915 else if ( !isInside
&& !m_beenInside
)
917 // Popup is shown but the cursor is not inside, nor it has been
918 relayToButton
= true;
924 wxWindow
* btn
= m_combo
->GetButton();
926 btn
->GetEventHandler()->ProcessEvent(event
);
928 // Bypass the event handling mechanism. Using it would be
929 // confusing for the platform-specific wxComboCtrl
931 m_combo
->HandleButtonMouseEvent(event
, 0);
935 // ----------------------------------------------------------------------------
936 // wxComboCtrlTextCtrl
937 // ----------------------------------------------------------------------------
939 class wxComboCtrlTextCtrl
: public wxTextCtrl
942 wxComboCtrlTextCtrl() : wxTextCtrl() { }
943 virtual ~wxComboCtrlTextCtrl() { }
945 virtual wxWindow
*GetMainWindowOfCompositeControl()
947 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
949 // Returning this instead of just 'parent' lets FindFocus work
950 // correctly even when parent control is a child of a composite
951 // generic control (as is case with wxGenericDatePickerCtrl).
952 return combo
->GetMainWindowOfCompositeControl();
956 // ----------------------------------------------------------------------------
958 // ----------------------------------------------------------------------------
961 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
962 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
963 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
964 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
965 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
966 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
967 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
968 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
969 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
973 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
975 void wxComboCtrlBase::Init()
979 m_popupWinState
= Hidden
;
982 m_popupInterface
= NULL
;
984 m_popupEvtHandler
= NULL
;
985 m_textEvtHandler
= NULL
;
987 #if INSTALL_TOPLEV_HANDLER
988 m_toplevEvtHandler
= NULL
;
991 m_mainCtrlWnd
= this;
994 m_widthMinPopup
= -1;
996 m_widthCustomPaint
= 0;
997 m_widthCustomBorder
= 0;
1000 m_btnWidDefault
= 0;
1001 m_blankButtonBg
= false;
1002 m_ignoreEvtText
= 0;
1003 m_popupWinType
= POPUPWIN_NONE
;
1004 m_btnWid
= m_btnHei
= -1;
1005 m_btnSide
= wxRIGHT
;
1012 m_textCtrlStyle
= 0;
1013 m_timeCanAcceptClick
= 0;
1015 m_resetFocus
= false;
1016 m_hasTcBgCol
= false;
1019 bool wxComboCtrlBase::Create(wxWindow
*parent
,
1021 const wxString
& value
,
1025 const wxValidator
& validator
,
1026 const wxString
& name
)
1028 if ( !wxControl::Create(parent
,
1032 style
| wxWANTS_CHARS
,
1037 m_valueString
= value
;
1041 m_marginLeft
= GetNativeTextIndent();
1043 m_iFlags
|= wxCC_IFLAG_CREATED
;
1045 // If x and y indicate valid size, wxSizeEvent won't be
1046 // emitted automatically, so we need to add artificial one.
1047 if ( size
.x
> 0 && size
.y
> 0 )
1049 wxSizeEvent
evt(size
,GetId());
1050 evt
.SetEventObject(this);
1051 GetEventHandler()->AddPendingEvent(evt
);
1057 void wxComboCtrlBase::InstallInputHandlers()
1061 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1062 m_text
->PushEventHandler(m_textEvtHandler
);
1067 wxComboCtrlBase::CreateTextCtrl(int style
)
1069 if ( !(m_windowStyle
& wxCB_READONLY
) )
1074 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1075 // not used by the wxPropertyGrid and therefore the tab is processed by
1076 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1077 // navigation event is then sent to the wrong window.
1078 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1080 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1081 style
|= wxTE_PROCESS_ENTER
;
1083 // Ignore EVT_TEXT generated by the constructor (but only
1084 // if the event redirector already exists)
1085 // NB: This must be " = 1" instead of "++";
1086 if ( m_textEvtHandler
)
1087 m_ignoreEvtText
= 1;
1089 m_ignoreEvtText
= 0;
1091 m_text
= new wxComboCtrlTextCtrl();
1092 m_text
->Create(this, wxID_ANY
, m_valueString
,
1093 wxDefaultPosition
, wxSize(10,-1),
1096 // Connecting the events is currently the most reliable way
1097 wxWindowID id
= m_text
->GetId();
1098 m_text
->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1099 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1101 m_text
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1102 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1105 m_text
->SetHint(m_hintText
);
1109 void wxComboCtrlBase::OnThemeChange()
1111 // Because wxComboCtrl has transparent parts on most platforms, we
1112 // don't want to touch the actual background colour. Instead, we just
1113 // usually re-obtain m_tcBgCol here.
1115 #if defined(__WXMSW__) || defined(__WXGTK__)
1116 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1118 wxVisualAttributes vattrs
;
1119 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1120 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1123 if ( !m_hasTcBgCol
)
1124 m_tcBgCol
= vattrs
.colBg
;
1127 // Only change the colours if application has not specified
1131 SetOwnForegroundColour(vattrs
.colFg
);
1133 if ( !HasTransparentBackground() )
1135 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1137 #endif // !__WXMAC__
1140 wxComboCtrlBase::~wxComboCtrlBase()
1145 #if INSTALL_TOPLEV_HANDLER
1146 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1147 m_toplevEvtHandler
= NULL
;
1153 m_text
->RemoveEventHandler(m_textEvtHandler
);
1155 delete m_textEvtHandler
;
1159 // ----------------------------------------------------------------------------
1161 // ----------------------------------------------------------------------------
1163 // Recalculates button and textctrl areas
1164 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1166 wxSize sz
= GetClientSize();
1167 int customBorder
= m_widthCustomBorder
;
1168 int btnBorder
; // border for button only
1170 // check if button should really be outside the border: we'll do it it if
1171 // its platform default or bitmap+pushbutton background is used, but not if
1172 // there is vertical size adjustment or horizontal spacing.
1173 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1174 (m_bmpNormal
.IsOk() && m_blankButtonBg
) ) &&
1175 m_btnSpacingX
== 0 &&
1178 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1181 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1182 m_btnSpacingX
== 0 && !m_bmpNormal
.IsOk() )
1184 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1189 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1190 btnBorder
= customBorder
;
1193 // Defaul indentation
1194 if ( m_marginLeft
< 0 )
1195 m_marginLeft
= GetNativeTextIndent();
1197 int butWidth
= btnWidth
;
1199 if ( butWidth
<= 0 )
1200 butWidth
= m_btnWidDefault
;
1202 m_btnWidDefault
= butWidth
;
1204 if ( butWidth
<= 0 )
1207 int butHeight
= sz
.y
- btnBorder
*2;
1209 // Adjust button width
1211 butWidth
= m_btnWid
;
1214 // Adjust button width to match aspect ratio
1215 // (but only if control is smaller than best size).
1216 int bestHeight
= GetBestSize().y
;
1217 int height
= GetSize().y
;
1219 if ( height
< bestHeight
)
1221 // Make very small buttons square, as it makes
1222 // them accommodate arrow image better and still
1225 butWidth
= (height
*butWidth
)/bestHeight
;
1227 butWidth
= butHeight
;
1231 // Adjust button height
1233 butHeight
= m_btnHei
;
1235 // Use size of normal bitmap if...
1238 // button width is set to default and blank button bg is not drawn
1239 if ( m_bmpNormal
.IsOk() )
1241 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1242 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1244 // If drawing blank button background, we need to add some margin.
1245 if ( m_blankButtonBg
)
1247 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1248 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1251 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1252 butWidth
= bmpReqWidth
;
1253 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1254 butHeight
= bmpReqHeight
;
1256 // Need to fix height?
1257 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1259 int newY
= butHeight
+(customBorder
*2);
1260 SetClientSize(wxDefaultCoord
,newY
);
1261 if ( m_bmpNormal
.IsOk() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1262 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1264 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1270 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1272 m_btnSize
.x
= butWidth
;
1273 m_btnSize
.y
= butHeight
;
1275 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1276 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1277 m_btnArea
.width
= butAreaWid
;
1278 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1280 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1281 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1282 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1283 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1288 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1289 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1294 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1299 wxSize sz
= GetClientSize();
1301 int customBorder
= m_widthCustomBorder
;
1302 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1306 if ( !m_widthCustomPaint
)
1308 // No special custom paint area - we can use 0 left margin
1310 if ( m_text
->SetMargins(0) )
1311 textCtrlXAdjust
= 0;
1312 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1316 // There is special custom paint area - it is better to
1317 // use some margin with the wxTextCtrl.
1318 m_text
->SetMargins(m_marginLeft
);
1319 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1320 m_marginLeft
+ textCtrlXAdjust
;
1323 // Centre textctrl vertically, if needed
1324 #if !TEXTCTRL_TEXT_CENTERED
1325 int tcSizeY
= m_text
->GetBestSize().y
;
1326 int diff0
= sz
.y
- tcSizeY
;
1327 int y
= textCtrlYAdjust
+ (diff0
/2);
1329 wxUnusedVar(textCtrlYAdjust
);
1333 if ( y
< customBorder
)
1338 m_tcArea
.width
- m_tcArea
.x
- x
,
1341 // Make sure textctrl doesn't exceed the bottom custom border
1342 wxSize tsz
= m_text
->GetSize();
1343 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1346 tsz
.y
= tsz
.y
- diff1
- 1;
1347 m_text
->SetSize(tsz
);
1352 // If it has border, have textctrl fill the entire text field.
1353 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1355 m_tcArea
.width
- m_widthCustomPaint
,
1360 wxSize
wxComboCtrlBase::DoGetBestSize() const
1362 wxSize
sizeText(150,0);
1365 sizeText
= m_text
->GetBestSize();
1367 // TODO: Better method to calculate close-to-native control height.
1370 if ( m_font
.IsOk() )
1371 fhei
= (m_font
.GetPointSize()*2) + 5;
1372 else if ( wxNORMAL_FONT
->IsOk() )
1373 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1375 fhei
= sizeText
.y
+ 4;
1377 // Need to force height to accommodate bitmap?
1378 int btnSizeY
= m_btnSize
.y
;
1379 if ( m_bmpNormal
.IsOk() && fhei
< btnSizeY
)
1382 // Control height doesn't depend on border
1385 int border = m_windowStyle & wxBORDER_MASK;
1386 if ( border == wxSIMPLE_BORDER )
1388 else if ( border == wxNO_BORDER )
1389 fhei += (m_widthCustomBorder*2);
1395 // Final adjustments
1401 // these are the numbers from the HIG:
1402 switch ( m_windowVariant
)
1404 case wxWINDOW_VARIANT_NORMAL
:
1408 case wxWINDOW_VARIANT_SMALL
:
1411 case wxWINDOW_VARIANT_MINI
:
1417 fhei
+= 2 * FOCUS_RING
;
1418 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1420 wxSize
ret(width
, fhei
);
1425 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1430 // defined by actual wxComboCtrls
1436 // ----------------------------------------------------------------------------
1437 // standard operations
1438 // ----------------------------------------------------------------------------
1440 bool wxComboCtrlBase::Enable(bool enable
)
1442 if ( !wxControl::Enable(enable
) )
1446 m_btn
->Enable(enable
);
1448 m_text
->Enable(enable
);
1455 bool wxComboCtrlBase::Show(bool show
)
1457 if ( !wxControl::Show(show
) )
1469 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1471 if ( !wxControl::SetFont(font
) )
1476 // Without hiding the wxTextCtrl there would be some
1477 // visible 'flicker' (at least on Windows XP).
1479 m_text
->SetFont(font
);
1488 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1490 wxControl::DoSetToolTip(tooltip
);
1492 // Set tool tip for button and text box
1495 const wxString
&tip
= tooltip
->GetTip();
1496 if ( m_text
) m_text
->SetToolTip(tip
);
1497 if ( m_btn
) m_btn
->SetToolTip(tip
);
1501 if ( m_text
) m_text
->SetToolTip( NULL
);
1502 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1505 #endif // wxUSE_TOOLTIPS
1507 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1509 if ( wxControl::SetForegroundColour(colour
) )
1512 m_text
->SetForegroundColour(colour
);
1518 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1521 m_text
->SetBackgroundColour(colour
);
1523 m_hasTcBgCol
= true;
1527 wxColour
wxComboCtrlBase::GetBackgroundColour() const
1530 return m_text
->GetBackgroundColour();
1534 // ----------------------------------------------------------------------------
1536 // ----------------------------------------------------------------------------
1538 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1539 // prepare combo box background on area in a way typical on platform
1540 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1542 wxSize sz
= GetClientSize();
1544 bool doDrawFocusRect
; // also selected
1546 // For smaller size control (and for disabled background) use less spacing
1550 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1553 isEnabled
= IsEnabled();
1554 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1556 // Windows-style: for smaller size control (and for disabled background) use less spacing
1557 focusSpacingX
= isEnabled
? 2 : 1;
1558 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1562 // Drawing a list item
1563 isEnabled
= true; // they are never disabled
1564 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1570 // Set the background sub-rectangle for selection, disabled etc
1571 wxRect
selRect(rect
);
1572 selRect
.y
+= focusSpacingY
;
1573 selRect
.height
-= (focusSpacingY
*2);
1577 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1578 wcp
+= m_widthCustomPaint
;
1580 selRect
.x
+= wcp
+ focusSpacingX
;
1581 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1586 bool doDrawSelRect
= true;
1588 // Determine foreground colour
1591 if ( doDrawFocusRect
)
1593 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1595 else if ( m_hasFgCol
)
1597 // Honour the custom foreground colour
1598 fgCol
= GetForegroundColour();
1602 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1607 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1610 // Determine background colour
1613 if ( doDrawFocusRect
)
1615 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1617 else if ( m_hasTcBgCol
)
1619 // Honour the custom background colour
1624 #ifndef __WXMAC__ // see note in OnThemeChange
1625 doDrawSelRect
= false;
1626 bgCol
= GetBackgroundColour();
1628 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1634 #ifndef __WXMAC__ // see note in OnThemeChange
1635 bgCol
= GetBackgroundColour();
1637 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1641 dc
.SetTextForeground( fgCol
);
1642 dc
.SetBrush( bgCol
);
1643 if ( doDrawSelRect
)
1646 dc
.DrawRectangle( selRect
);
1649 // Don't clip exactly to the selection rectangle so we can draw
1650 // to the non-selected area in front of it.
1651 wxRect
clipRect(rect
.x
,rect
.y
,
1652 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1653 dc
.SetClippingRegion(clipRect
);
1656 // Save the library size a bit for platforms that re-implement this.
1657 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1662 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1664 int drawState
= m_btnState
;
1666 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1667 GetPopupWindowState() >= Animating
)
1668 drawState
|= wxCONTROL_PRESSED
;
1670 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1671 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1675 // Make sure area is not larger than the control
1676 if ( drawRect
.y
< rect
.y
)
1677 drawRect
.y
= rect
.y
;
1678 if ( drawRect
.height
> rect
.height
)
1679 drawRect
.height
= rect
.height
;
1681 bool enabled
= IsEnabled();
1684 drawState
|= wxCONTROL_DISABLED
;
1686 // Need to clear button background even if m_btn is present
1687 // and also when using custom bitmap for the button
1688 if ( (flags
& Button_PaintBackground
) &&
1689 (!HasTransparentBackground() ||
1690 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1694 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1695 bgCol
= GetParent()->GetBackgroundColour();
1697 bgCol
= GetBackgroundColour();
1701 dc
.DrawRectangle(rect
);
1704 if ( !m_bmpNormal
.IsOk() )
1706 if ( flags
& Button_BitmapOnly
)
1709 // Draw standard button
1710 wxRendererNative::Get().DrawComboBoxDropButton(this,
1722 pBmp
= &m_bmpDisabled
;
1723 else if ( m_btnState
& wxCONTROL_PRESSED
)
1724 pBmp
= &m_bmpPressed
;
1725 else if ( m_btnState
& wxCONTROL_CURRENT
)
1728 pBmp
= &m_bmpNormal
;
1730 if ( m_blankButtonBg
)
1732 if ( !(flags
& Button_BitmapOnly
) )
1734 wxRendererNative::Get().DrawPushButton(this,
1741 // Draw bitmap centered in drawRect
1742 dc
.DrawBitmap(*pBmp
,
1743 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1744 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1749 void wxComboCtrlBase::RecalcAndRefresh()
1753 wxSizeEvent
evt(GetSize(),GetId());
1754 evt
.SetEventObject(this);
1755 GetEventHandler()->ProcessEvent(evt
);
1760 // ----------------------------------------------------------------------------
1761 // miscellaneous event handlers
1762 // ----------------------------------------------------------------------------
1764 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1766 // Avoid infinite recursion
1767 if ( event
.GetEventObject() == this )
1773 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1775 if ( m_ignoreEvtText
> 0 )
1782 // For safety, completely re-create a new wxCommandEvent
1783 wxCommandEvent
evt2(event
);
1784 evt2
.SetId(GetId());
1785 evt2
.SetEventObject(this);
1786 HandleWindowEvent(evt2
);
1788 event
.StopPropagation();
1791 // call if cursor is on button area or mouse is captured for the button
1792 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1795 int type
= event
.GetEventType();
1797 if ( type
== wxEVT_MOTION
)
1799 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1800 IsPopupWindowState(Hidden
) )
1802 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1804 // Mouse hover begins
1805 m_btnState
|= wxCONTROL_CURRENT
;
1806 if ( HasCapture() ) // Retain pressed state.
1807 m_btnState
|= wxCONTROL_PRESSED
;
1811 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1814 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1818 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1820 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1822 m_btnState
|= wxCONTROL_PRESSED
;
1825 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1828 // If showing popup now, do not capture mouse or there will be interference
1832 else if ( type
== wxEVT_LEFT_UP
)
1835 // Only accept event if mouse was left-press was previously accepted
1839 if ( m_btnState
& wxCONTROL_PRESSED
)
1841 // If mouse was inside, fire the click event.
1842 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1844 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1848 m_btnState
&= ~(wxCONTROL_PRESSED
);
1852 else if ( type
== wxEVT_LEAVE_WINDOW
)
1854 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1856 m_btnState
&= ~(wxCONTROL_CURRENT
);
1859 if ( IsPopupWindowState(Hidden
) )
1861 m_btnState
&= ~(wxCONTROL_PRESSED
);
1869 // Never have 'hot' state when popup is being shown
1870 // (this is mostly needed because of the animation).
1871 if ( !IsPopupWindowState(Hidden
) )
1872 m_btnState
&= ~wxCONTROL_CURRENT
;
1877 // returns true if event was consumed or filtered
1878 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1879 int WXUNUSED(flags
) )
1881 wxLongLong t
= ::wxGetLocalTimeMillis();
1882 int evtType
= event
.GetEventType();
1884 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1885 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1887 if ( IsPopupWindowState(Visible
) &&
1888 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1896 // Filter out clicks on button immediately after popup dismiss
1897 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1899 event
.SetEventType(0);
1906 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1908 int evtType
= event
.GetEventType();
1910 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1911 (m_windowStyle
& wxCB_READONLY
) )
1913 if ( GetPopupWindowState() >= Animating
)
1915 #if USES_WXPOPUPWINDOW
1916 // Click here always hides the popup.
1917 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1923 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1925 // In read-only mode, clicking the text is the
1926 // same as clicking the button.
1929 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1931 //if ( m_popupInterface->CycleValue() )
1933 if ( m_popupInterface
)
1934 m_popupInterface
->OnComboDoubleClick();
1938 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1940 if ( IsPopupShown() )
1942 // relay (some) mouse events to the popup
1943 m_popup
->GetEventHandler()->ProcessEvent(event
);
1945 else if ( event
.GetWheelAxis() == 0 &&
1946 event
.GetWheelRotation() != 0 &&
1947 event
.GetModifiers() == 0 )
1949 // Translate mousewheel actions into key up/down. This is
1950 // the simplest way of getting native behaviour: scrolling the
1951 // wheel moves selection up/down by one item.
1952 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1953 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1956 GetEventHandler()->ProcessEvent(kevent
);
1969 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1971 if ( IsPopupShown() )
1973 // pass it to the popped up control
1974 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1978 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1980 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1982 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1986 if ( IsKeyPopupToggle(event
) )
1992 int comboStyle
= GetWindowStyle();
1993 wxComboPopup
* popupInterface
= GetPopupControl();
1995 if ( !popupInterface
)
2001 int keycode
= event
.GetKeyCode();
2003 if ( (comboStyle
& wxCB_READONLY
) ||
2004 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
2006 popupInterface
->OnComboKeyEvent(event
);
2013 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
2015 if ( IsPopupShown() )
2017 // pass it to the popped up control
2018 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2022 wxComboPopup
* popupInterface
= GetPopupControl();
2023 if ( popupInterface
)
2025 popupInterface
->OnComboCharEvent(event
);
2034 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
2036 // On Mac, this leads to infinite recursion and eventually a crash
2038 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2040 wxWindow
* tc
= GetTextCtrl();
2041 if ( tc
&& tc
!= DoFindFocus() )
2051 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2055 m_resetFocus
= false;
2056 wxWindow
* tc
= GetTextCtrl();
2062 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2065 // left margin may also have changed
2066 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2067 m_marginLeft
= GetNativeTextIndent();
2071 // ----------------------------------------------------------------------------
2073 // ----------------------------------------------------------------------------
2075 // Create popup window and the child control
2076 void wxComboCtrlBase::CreatePopup()
2078 wxComboPopup
* popupInterface
= m_popupInterface
;
2083 #ifdef wxComboPopupWindowBase2
2084 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2086 #if !USES_GENERICTLW
2087 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2089 int tlwFlags
= wxNO_BORDER
;
2090 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2091 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2094 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2095 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2096 wxPoint(-21,-21), wxSize(20, 20),
2099 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2100 wxPoint(-21,-21), wxSize(20, 20),
2104 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2107 #endif // wxComboPopupWindowBase2
2109 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2110 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2112 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2113 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2116 popupInterface
->Create(m_winPopup
);
2117 m_popup
= popup
= popupInterface
->GetControl();
2119 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2120 popup
->PushEventHandler( m_popupEvtHandler
);
2122 // This may be helpful on some platforms
2123 // (eg. it bypasses a wxGTK popupwindow bug where
2124 // window is not initially hidden when it should be)
2127 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2130 // Destroy popup window and the child control
2131 void wxComboCtrlBase::DestroyPopup()
2136 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2138 wxDELETE(m_popupEvtHandler
);
2140 if ( m_popupInterface
)
2142 // NB: DestroyPopup() performs 'delete this'.
2143 m_popupInterface
->DestroyPopup();
2144 m_popupInterface
= NULL
;
2149 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2150 wxDELETE(m_popupWinEvtHandler
);
2151 m_winPopup
->Destroy();
2158 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2160 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2164 iface
->InitBase(this);
2167 m_popupInterface
= iface
;
2169 if ( !iface
->LazyCreate() )
2178 // This must be done after creation
2179 if ( !m_valueString
.empty() )
2181 iface
->SetStringValue(m_valueString
);
2186 // Ensures there is atleast the default popup
2187 void wxComboCtrlBase::EnsurePopupControl()
2189 if ( !m_popupInterface
)
2190 SetPopupControl(NULL
);
2193 void wxComboCtrlBase::OnButtonClick()
2195 // Derived classes can override this method for totally custom
2197 switch ( GetPopupWindowState() )
2214 void wxComboCtrlBase::Popup()
2216 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2217 event
.SetEventObject(this);
2218 HandleWindowEvent(event
);
2223 void wxComboCtrlBase::ShowPopup()
2225 EnsurePopupControl();
2226 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2228 if ( IsPopupWindowState(Animating
) )
2233 // Space above and below
2239 wxSize ctrlSz
= GetSize();
2241 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2242 scrPos
= GetParent()->ClientToScreen(GetPosition());
2244 spaceAbove
= scrPos
.y
;
2245 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2247 maxHeightPopup
= spaceBelow
;
2248 if ( spaceAbove
> spaceBelow
)
2249 maxHeightPopup
= spaceAbove
;
2252 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2254 if ( widthPopup
< m_widthMinPopup
)
2255 widthPopup
= m_widthMinPopup
;
2257 wxWindow
* winPopup
= m_winPopup
;
2260 // Need to disable tab traversal of parent
2262 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2263 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2264 // that if transient popup is open, then tab traversal is to be ignored.
2265 // However, I think this code would still be needed for cases where
2266 // transient popup doesn't work yet (wxWinCE?).
2267 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2268 wxWindow
* parent
= mainCtrl
->GetParent();
2269 int parentFlags
= parent
->GetWindowStyle();
2270 if ( parentFlags
& wxTAB_TRAVERSAL
)
2272 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2273 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2279 winPopup
= m_winPopup
;
2289 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2291 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2292 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2295 popup
->SetSize(adjustedSize
);
2297 m_popupInterface
->OnPopup();
2300 // Reposition and resize popup window
2303 wxSize szp
= popup
->GetSize();
2306 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2308 // Default anchor is wxLEFT
2309 int anchorSide
= m_anchorSide
;
2311 anchorSide
= wxLEFT
;
2313 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2314 int leftX
= scrPos
.x
- m_extLeft
;
2316 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2319 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2321 // If there is not enough horizontal space, anchor on the other side.
2322 // If there is no space even then, place the popup at x 0.
2323 if ( anchorSide
== wxRIGHT
)
2327 if ( (leftX
+szp
.x
) < screenWidth
)
2328 anchorSide
= wxLEFT
;
2335 if ( (leftX
+szp
.x
) >= screenWidth
)
2338 anchorSide
= wxRIGHT
;
2344 // Select x coordinate according to the anchor side
2345 if ( anchorSide
== wxRIGHT
)
2347 else if ( anchorSide
== wxLEFT
)
2352 int showFlags
= CanDeferShow
;
2354 if ( spaceBelow
< szp
.y
)
2356 popupY
= scrPos
.y
- szp
.y
;
2357 showFlags
|= ShowAbove
;
2360 #if INSTALL_TOPLEV_HANDLER
2361 // Put top level window event handler into place
2362 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2364 if ( !m_toplevEvtHandler
)
2365 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2367 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2369 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2370 toplev
->PushEventHandler( m_toplevEvtHandler
);
2374 // Set string selection (must be this way instead of SetStringSelection)
2377 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2378 m_text
->SelectAll();
2380 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2384 // This is neede since focus/selection indication may change when popup is shown
2388 // This must be after SetStringValue
2389 m_popupWinState
= Animating
;
2391 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2394 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2395 AnimateShow( popupWinRect
, showFlags
) )
2397 DoShowPopup( popupWinRect
, showFlags
);
2401 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2406 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2408 wxWindow
* winPopup
= m_winPopup
;
2410 if ( IsPopupWindowState(Animating
) )
2412 // Make sure the popup window is shown in the right position.
2413 // Should not matter even if animation already did this.
2415 // Some platforms (GTK) may like SetSize and Move to be separate
2416 // (though the bug was probably fixed).
2417 winPopup
->SetSize( rect
);
2419 #if USES_WXPOPUPTRANSIENTWINDOW
2420 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2421 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2426 m_popupWinState
= Visible
;
2428 // If popup window was a generic top-level window, or the
2429 // wxPopupWindow implemenation on this platform is classified as
2430 // perfect, then we should be able to safely set focus to the popup
2432 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2433 m_popup
->SetFocus();
2435 else if ( IsPopupWindowState(Hidden
) )
2437 // Animation was aborted
2439 wxASSERT( !winPopup
->IsShown() );
2441 m_popupWinState
= Hidden
;
2447 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2449 // Just in case, avoid double dismiss
2450 if ( IsPopupWindowState(Hidden
) )
2453 // This must be set before focus - otherwise there will be recursive
2454 // OnPopupDismisses.
2455 m_popupWinState
= Hidden
;
2458 m_winPopup
->Disable();
2460 // Inform popup control itself
2461 m_popupInterface
->OnDismiss();
2463 if ( m_popupEvtHandler
)
2464 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2466 #if INSTALL_TOPLEV_HANDLER
2467 // Remove top level window event handler
2468 if ( m_toplevEvtHandler
)
2470 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2472 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2476 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2478 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2479 m_timeCanAcceptClick
+= 150;
2481 // If cursor not on dropdown button, then clear its state
2482 // (technically not required by all ports, but do it for all just in case)
2483 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2486 // Return parent's tab traversal flag.
2487 // See ShowPopup for notes.
2488 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2490 wxWindow
* parent
= GetParent();
2491 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2492 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2495 // refresh control (necessary even if m_text)
2500 if ( generateEvent
)
2502 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2503 event
.SetEventObject(this);
2504 HandleWindowEvent(event
);
2508 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2510 // Should be able to call this without popup interface
2511 if ( IsPopupWindowState(Hidden
) )
2514 // transfer value and show it in textctrl, if any
2515 if ( !IsPopupWindowState(Animating
) )
2516 SetValueByUser( m_popupInterface
->GetStringValue() );
2520 OnPopupDismiss(generateEvent
);
2523 // ----------------------------------------------------------------------------
2524 // customization methods
2525 // ----------------------------------------------------------------------------
2527 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2528 int side
, int spacingX
)
2533 m_btnSpacingX
= spacingX
;
2535 if ( width
> 0 || height
> 0 || spacingX
)
2536 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2541 wxSize
wxComboCtrlBase::GetButtonSize()
2543 if ( m_btnSize
.x
> 0 )
2546 wxSize
retSize(m_btnWid
,m_btnHei
);
2548 // Need to call CalculateAreas now if button size is
2549 // is not explicitly specified.
2550 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2554 retSize
= m_btnSize
;
2560 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2562 const wxBitmap
& bmpPressed
,
2563 const wxBitmap
& bmpHover
,
2564 const wxBitmap
& bmpDisabled
)
2566 m_bmpNormal
= bmpNormal
;
2567 m_blankButtonBg
= blankButtonBg
;
2569 if ( bmpPressed
.IsOk() )
2570 m_bmpPressed
= bmpPressed
;
2572 m_bmpPressed
= bmpNormal
;
2574 if ( bmpHover
.IsOk() )
2575 m_bmpHover
= bmpHover
;
2577 m_bmpHover
= bmpNormal
;
2579 if ( bmpDisabled
.IsOk() )
2580 m_bmpDisabled
= bmpDisabled
;
2582 m_bmpDisabled
= bmpNormal
;
2587 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2591 // move textctrl accordingly
2592 wxRect r
= m_text
->GetRect();
2593 int inc
= width
- m_widthCustomPaint
;
2596 m_text
->SetSize( r
);
2599 m_widthCustomPaint
= width
;
2604 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2606 // For general sanity's sake, we ignore top margin. Instead
2607 // we will always try to center the text vertically.
2610 if ( margins
.x
!= -1 )
2612 m_marginLeft
= margins
.x
;
2613 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2617 m_marginLeft
= GetNativeTextIndent();
2618 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2621 if ( margins
.y
!= -1 )
2631 wxPoint
wxComboCtrlBase::DoGetMargins() const
2633 return wxPoint(m_marginLeft
, -1);
2636 #if WXWIN_COMPATIBILITY_2_8
2637 void wxComboCtrlBase::SetTextIndent( int indent
)
2641 m_marginLeft
= GetNativeTextIndent();
2642 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2646 m_marginLeft
= indent
;
2647 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2653 wxCoord
wxComboCtrlBase::GetTextIndent() const
2655 return m_marginLeft
;
2659 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2661 return DEFAULT_TEXT_INDENT
;
2664 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2666 m_textCtrlStyle
= style
;
2669 m_text
->SetWindowStyle(style
);
2672 // ----------------------------------------------------------------------------
2673 // wxTextEntry interface
2674 // ----------------------------------------------------------------------------
2676 wxString
wxComboCtrlBase::DoGetValue() const
2679 return m_text
->GetValue();
2680 return m_valueString
;
2683 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2686 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2689 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2691 // Note: before wxComboCtrl inherited from wxTextEntry,
2692 // this code used to be in SetValueWithEvent().
2694 // Since wxComboPopup may want to paint the combo as well, we need
2695 // to set the string value here (as well as sometimes in ShowPopup).
2696 if ( m_valueString
!= value
)
2699 wxString trueValue
= value
;
2701 // Conform to wxComboBox behaviour: read-only control can only accept
2702 // valid list items and empty string
2703 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2705 found
= m_popupInterface
->FindItem(value
,
2711 m_valueString
= trueValue
;
2713 EnsurePopupControl();
2715 if ( m_popupInterface
)
2716 m_popupInterface
->SetStringValue(trueValue
);
2723 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2725 // NB: Order of function calls is important here. Otherwise
2726 // the SelectAll() may not work.
2730 m_text
->SetValue(value
);
2732 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2733 m_text
->SelectAll();
2739 // In this SetValue variant wxComboPopup::SetStringValue is not called
2740 void wxComboCtrlBase::SetText(const wxString
& value
)
2742 // Unlike in SetValue(), this must be called here or
2743 // the behaviour will no be consistent in readonlys.
2744 EnsurePopupControl();
2746 m_valueString
= value
;
2751 m_text
->SetValue( value
);
2757 void wxComboCtrlBase::Copy()
2763 void wxComboCtrlBase::Cut()
2769 void wxComboCtrlBase::Paste()
2775 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2778 m_text
->SetInsertionPoint(pos
);
2781 long wxComboCtrlBase::GetInsertionPoint() const
2784 return m_text
->GetInsertionPoint();
2789 long wxComboCtrlBase::GetLastPosition() const
2792 return m_text
->GetLastPosition();
2797 void wxComboCtrlBase::WriteText(const wxString
& text
)
2801 m_text
->WriteText(text
);
2802 OnSetValue(m_text
->GetValue());
2810 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2814 if ( flags
& SetValue_SendEvent
)
2815 m_text
->SetValue(value
);
2817 m_text
->ChangeValue(value
);
2823 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2827 m_text
->Replace(from
, to
, value
);
2828 OnSetValue(m_text
->GetValue());
2832 void wxComboCtrlBase::Remove(long from
, long to
)
2836 m_text
->Remove(from
, to
);
2837 OnSetValue(m_text
->GetValue());
2841 void wxComboCtrlBase::SetSelection(long from
, long to
)
2844 m_text
->SetSelection(from
, to
);
2847 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2851 m_text
->GetSelection(from
, to
);
2860 bool wxComboCtrlBase::IsEditable() const
2863 return m_text
->IsEditable();
2867 void wxComboCtrlBase::SetEditable(bool editable
)
2870 m_text
->SetEditable(editable
);
2873 void wxComboCtrlBase::Undo()
2879 void wxComboCtrlBase::Redo()
2885 bool wxComboCtrlBase::CanUndo() const
2888 return m_text
->CanUndo();
2893 bool wxComboCtrlBase::CanRedo() const
2896 return m_text
->CanRedo();
2901 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2906 res
= m_text
->SetHint(hint
);
2911 wxString
wxComboCtrlBase::GetHint() const
2916 #endif // wxUSE_COMBOCTRL