1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
7 // Copyright: (c) 2005 Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 #include "wx/wxprec.h"
28 #include "wx/combobox.h"
29 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr
[] = "comboBox";
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 wxDEFINE_FLAGS( wxComboBoxStyle
)
36 wxBEGIN_FLAGS( wxComboBoxStyle
)
37 // new style border flags, we put them first to
38 // use them for streaming out
39 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
40 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
41 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
42 wxFLAGS_MEMBER(wxBORDER_RAISED
)
43 wxFLAGS_MEMBER(wxBORDER_STATIC
)
44 wxFLAGS_MEMBER(wxBORDER_NONE
)
46 // old style border flags
47 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
48 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
49 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
50 wxFLAGS_MEMBER(wxRAISED_BORDER
)
51 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
52 wxFLAGS_MEMBER(wxBORDER
)
54 // standard window styles
55 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
56 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
57 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
58 wxFLAGS_MEMBER(wxWANTS_CHARS
)
59 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
60 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
61 wxFLAGS_MEMBER(wxVSCROLL
)
62 wxFLAGS_MEMBER(wxHSCROLL
)
64 wxFLAGS_MEMBER(wxCB_SIMPLE
)
65 wxFLAGS_MEMBER(wxCB_SORT
)
66 wxFLAGS_MEMBER(wxCB_READONLY
)
67 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
69 wxEND_FLAGS( wxComboBoxStyle
)
71 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
73 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
74 wxEVENT_PROPERTY( Select
, wxEVT_COMBOBOX
, wxCommandEvent
)
75 wxEVENT_PROPERTY( TextEnter
, wxEVT_TEXT_ENTER
, wxCommandEvent
)
78 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
79 0 /*flags*/, wxT("Helpstring"), wxT("group"))
80 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
81 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
82 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
83 0 /*flags*/, wxT("Helpstring"), wxT("group"))
84 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
85 0 /*flags*/, wxT("Helpstring"), wxT("group"))
87 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
88 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
89 wxT("Helpstring"), wxT("group")) // style
90 wxEND_PROPERTIES_TABLE()
92 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
94 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
95 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
97 #endif // wxUSE_COMBOBOX
104 #include "wx/dcclient.h"
105 #include "wx/settings.h"
106 #include "wx/timer.h"
107 #include "wx/textctrl.h"
110 #include "wx/tooltip.h"
113 // ----------------------------------------------------------------------------
115 #define DEFAULT_DROPBUTTON_WIDTH 19
117 #define BMP_BUTTON_MARGIN 4
119 #define DEFAULT_POPUP_HEIGHT 400
121 #define DEFAULT_TEXT_INDENT 3
123 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
126 #if defined(__WXMSW__)
128 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
129 #include "wx/frame.h"
130 #define wxCC_GENERIC_TLW_IS_FRAME
131 #define wxComboCtrlGenericTLW wxFrame
133 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
134 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
135 // native controls work on it like normal.
136 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
137 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
138 #define FOCUS_RING 0 // No focus ring on wxMSW
140 //#undef wxUSE_POPUPWIN
141 //#define wxUSE_POPUPWIN 0
143 #elif defined(__WXGTK__)
145 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
146 // this bug: If wxDialog is hidden, its position becomes corrupt
147 // between hide and next show, but without internal coordinates being
148 // reflected (or something like that - atleast commenting out ->Hide()
149 // seemed to eliminate the position change).
151 #include "wx/dialog.h"
152 #define wxCC_GENERIC_TLW_IS_DIALOG
153 #define wxComboCtrlGenericTLW wxDialog
155 #if defined(__WXGTK20__)
156 # include "wx/gtk/private.h"
158 # include "wx/gtk1/private.h"
161 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
162 // 'perfect' popup, as it can successfully host child controls even in
163 // popups that are shown in modal dialogs.
165 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
166 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
167 // native controls work on it like normal.
168 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
169 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
170 #define FOCUS_RING 0 // No focus ring on wxGTK
172 #elif defined(__WXMAC__)
174 #include "wx/nonownedwnd.h"
175 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
176 #define wxComboCtrlGenericTLW wxNonOwnedWindow
178 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
179 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
180 // native controls work on it like normal.
181 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
182 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
183 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
185 #undef DEFAULT_DROPBUTTON_WIDTH
186 #define DEFAULT_DROPBUTTON_WIDTH 22
188 #define COMBO_MARGIN FOCUS_RING
192 #include "wx/dialog.h"
193 #define wxCC_GENERIC_TLW_IS_DIALOG
194 #define wxComboCtrlGenericTLW wxDialog
196 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
197 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
198 // native controls work on it like normal.
199 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
200 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
206 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
207 // what the wxUSE_POPUPWIN says.
208 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
209 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
210 #undef wxUSE_POPUPWIN
211 #define wxUSE_POPUPWIN 0
216 #include "wx/popupwin.h"
218 #undef USE_TRANSIENT_POPUP
219 #define USE_TRANSIENT_POPUP 0
223 // Define different types of popup windows
227 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
228 POPUPWIN_WXPOPUPWINDOW
= 2,
229 POPUPWIN_GENERICTLW
= 3
233 #if USE_TRANSIENT_POPUP
234 // wxPopupTransientWindow is implemented
236 #define wxComboPopupWindowBase wxPopupTransientWindow
237 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
238 #define USES_WXPOPUPTRANSIENTWINDOW 1
240 #if TRANSIENT_POPUPWIN_IS_PERFECT
242 #elif POPUPWIN_IS_PERFECT
243 #define wxComboPopupWindowBase2 wxPopupWindow
244 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
245 #define USES_WXPOPUPWINDOW 1
247 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
248 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
249 #define USES_GENERICTLW 1
253 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
255 #define wxComboPopupWindowBase wxPopupWindow
256 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
257 #define USES_WXPOPUPWINDOW 1
259 #if !POPUPWIN_IS_PERFECT
260 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
261 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
262 #define USES_GENERICTLW 1
266 // wxPopupWindow is not implemented
268 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
269 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
270 #define USES_GENERICTLW 1
275 #ifndef USES_WXPOPUPTRANSIENTWINDOW
276 #define USES_WXPOPUPTRANSIENTWINDOW 0
279 #ifndef USES_WXPOPUPWINDOW
280 #define USES_WXPOPUPWINDOW 0
283 #ifndef USES_GENERICTLW
284 #define USES_GENERICTLW 0
288 #if USES_WXPOPUPWINDOW
289 #define INSTALL_TOPLEV_HANDLER 1
291 #define INSTALL_TOPLEV_HANDLER 0
295 // Returns true if given popup window type can be classified as perfect
297 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
299 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
300 wxUnusedVar(popupWinType
);
303 return ( popupWinType
== POPUPWIN_GENERICTLW
304 #if POPUPWIN_IS_PERFECT
305 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
307 #if TRANSIENT_POPUPWIN_IS_PERFECT
308 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
317 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
321 // ----------------------------------------------------------------------------
322 // wxComboFrameEventHandler takes care of hiding the popup when events happen
323 // in its top level parent.
324 // ----------------------------------------------------------------------------
326 #if INSTALL_TOPLEV_HANDLER
329 // This will no longer be necessary after wxTransientPopupWindow
330 // works well on all platforms.
333 class wxComboFrameEventHandler
: public wxEvtHandler
336 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
337 virtual ~wxComboFrameEventHandler();
341 void OnIdle( wxIdleEvent
& event
);
342 void OnMouseEvent( wxMouseEvent
& event
);
343 void OnActivate( wxActivateEvent
& event
);
344 void OnResize( wxSizeEvent
& event
);
345 void OnMove( wxMoveEvent
& event
);
346 void OnMenuEvent( wxMenuEvent
& event
);
347 void OnClose( wxCloseEvent
& event
);
350 wxWindow
* m_focusStart
;
351 wxComboCtrlBase
* m_combo
;
354 DECLARE_EVENT_TABLE()
357 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
358 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
359 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
360 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
361 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
362 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
363 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
364 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
365 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
366 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
369 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
375 wxComboFrameEventHandler::~wxComboFrameEventHandler()
379 void wxComboFrameEventHandler::OnPopup()
381 m_focusStart
= ::wxWindow::FindFocus();
384 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
386 wxWindow
* winFocused
= ::wxWindow::FindFocus();
388 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
389 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
391 if ( !winFocused
|| (
392 winFocused
!= m_focusStart
&&
393 winFocused
!= popup
&&
394 winFocused
->GetParent() != popup
&&
395 winFocused
!= winpopup
&&
396 winFocused
->GetParent() != winpopup
&&
397 winFocused
!= m_combo
&&
398 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
->SelectAll();
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_TEXT
,
1099 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1101 m_text
->Connect(id
, wxEVT_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 int width
= m_text
? m_text
->GetBestSize().x
: 80;
1364 return GetSizeFromTextSize(width
);
1367 wxSize
wxComboCtrlBase::DoGetSizeFromTextSize(int xlen
, int ylen
) const
1369 // Calculate close-to-native control height
1373 #if wxUSE_COMBOBOX && (defined(__WXMSW__) || defined(__WXGTK__)) \
1374 && !defined(__WXUNIVERSAL__)
1375 wxComboBox
* cb
= new wxComboBox
;
1377 cb
->Create(const_cast<wxComboCtrlBase
*>(this), wxID_ANY
);
1378 if ( m_font
.IsOk() )
1379 cb
->SetFont(m_font
);
1380 fhei
= cb
->GetBestSize().y
;
1383 if ( m_font
.IsOk() )
1384 fhei
= (m_font
.GetPointSize()*2) + 5;
1385 else if ( wxNORMAL_FONT
->IsOk() )
1386 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1389 #endif // only for wxComboBox on MSW or GTK
1391 // Need to force height to accommodate bitmap?
1392 int btnSizeY
= m_btnSize
.y
;
1393 if ( m_bmpNormal
.IsOk() && fhei
< btnSizeY
)
1396 // Control height doesn't depend on border
1399 int border = m_windowStyle & wxBORDER_MASK;
1400 if ( border == wxSIMPLE_BORDER )
1402 else if ( border == wxNO_BORDER )
1403 fhei += (m_widthCustomBorder*2);
1410 // these are the numbers from the HIG:
1411 switch ( m_windowVariant
)
1413 case wxWINDOW_VARIANT_NORMAL
:
1417 case wxWINDOW_VARIANT_SMALL
:
1420 case wxWINDOW_VARIANT_MINI
:
1426 fhei
+= 2 * FOCUS_RING
;
1429 int fwid
= xlen
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1431 // Add the margins we have previously set
1432 wxPoint
marg( GetMargins() );
1433 fwid
+= wxMax(0, marg
.x
);
1434 fhei
+= wxMax(0, marg
.y
);
1437 fhei
+= ylen
- GetCharHeight();
1439 return wxSize(fwid
, fhei
);
1442 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1447 // defined by actual wxComboCtrls
1453 // ----------------------------------------------------------------------------
1454 // standard operations
1455 // ----------------------------------------------------------------------------
1457 bool wxComboCtrlBase::Enable(bool enable
)
1459 if ( !wxControl::Enable(enable
) )
1463 m_btn
->Enable(enable
);
1465 m_text
->Enable(enable
);
1472 bool wxComboCtrlBase::Show(bool show
)
1474 if ( !wxControl::Show(show
) )
1486 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1488 if ( !wxControl::SetFont(font
) )
1493 // Without hiding the wxTextCtrl there would be some
1494 // visible 'flicker' (at least on Windows XP).
1496 m_text
->SetFont(font
);
1505 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1507 wxControl::DoSetToolTip(tooltip
);
1509 // Set tool tip for button and text box
1512 const wxString
&tip
= tooltip
->GetTip();
1513 if ( m_text
) m_text
->SetToolTip(tip
);
1514 if ( m_btn
) m_btn
->SetToolTip(tip
);
1518 if ( m_text
) m_text
->SetToolTip( NULL
);
1519 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1522 #endif // wxUSE_TOOLTIPS
1524 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1526 if ( wxControl::SetForegroundColour(colour
) )
1529 m_text
->SetForegroundColour(colour
);
1535 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1538 m_text
->SetBackgroundColour(colour
);
1540 m_hasTcBgCol
= true;
1544 wxColour
wxComboCtrlBase::GetBackgroundColour() const
1547 return m_text
->GetBackgroundColour();
1551 // ----------------------------------------------------------------------------
1553 // ----------------------------------------------------------------------------
1555 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1556 // prepare combo box background on area in a way typical on platform
1557 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1559 wxSize sz
= GetClientSize();
1561 bool doDrawFocusRect
; // also selected
1563 // For smaller size control (and for disabled background) use less spacing
1567 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1570 isEnabled
= IsEnabled();
1571 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1573 // Windows-style: for smaller size control (and for disabled background) use less spacing
1574 focusSpacingX
= isEnabled
? 2 : 1;
1575 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1579 // Drawing a list item
1580 isEnabled
= true; // they are never disabled
1581 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1587 // Set the background sub-rectangle for selection, disabled etc
1588 wxRect
selRect(rect
);
1589 selRect
.y
+= focusSpacingY
;
1590 selRect
.height
-= (focusSpacingY
*2);
1594 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1595 wcp
+= m_widthCustomPaint
;
1597 selRect
.x
+= wcp
+ focusSpacingX
;
1598 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1603 bool doDrawSelRect
= true;
1605 // Determine foreground colour
1608 if ( doDrawFocusRect
)
1610 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1612 else if ( m_hasFgCol
)
1614 // Honour the custom foreground colour
1615 fgCol
= GetForegroundColour();
1619 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1624 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1627 // Determine background colour
1630 if ( doDrawFocusRect
)
1632 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1634 else if ( m_hasTcBgCol
)
1636 // Honour the custom background colour
1641 #ifndef __WXMAC__ // see note in OnThemeChange
1642 doDrawSelRect
= false;
1643 bgCol
= GetBackgroundColour();
1645 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1651 #ifndef __WXMAC__ // see note in OnThemeChange
1652 bgCol
= GetBackgroundColour();
1654 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1658 dc
.SetTextForeground( fgCol
);
1659 dc
.SetBrush( bgCol
);
1660 if ( doDrawSelRect
)
1663 dc
.DrawRectangle( selRect
);
1666 // Don't clip exactly to the selection rectangle so we can draw
1667 // to the non-selected area in front of it.
1668 wxRect
clipRect(rect
.x
,rect
.y
,
1669 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1670 dc
.SetClippingRegion(clipRect
);
1673 // Save the library size a bit for platforms that re-implement this.
1674 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1679 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1681 int drawState
= m_btnState
;
1683 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1684 GetPopupWindowState() >= Animating
)
1685 drawState
|= wxCONTROL_PRESSED
;
1687 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1688 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1692 // Make sure area is not larger than the control
1693 if ( drawRect
.y
< rect
.y
)
1694 drawRect
.y
= rect
.y
;
1695 if ( drawRect
.height
> rect
.height
)
1696 drawRect
.height
= rect
.height
;
1698 bool enabled
= IsEnabled();
1701 drawState
|= wxCONTROL_DISABLED
;
1703 // Need to clear button background even if m_btn is present
1704 // and also when using custom bitmap for the button
1705 if ( (flags
& Button_PaintBackground
) &&
1706 (!HasTransparentBackground() ||
1707 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1711 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1712 bgCol
= GetParent()->GetBackgroundColour();
1714 bgCol
= GetBackgroundColour();
1718 dc
.DrawRectangle(rect
);
1721 if ( !m_bmpNormal
.IsOk() )
1723 if ( flags
& Button_BitmapOnly
)
1726 // Draw standard button
1727 wxRendererNative::Get().DrawComboBoxDropButton(this,
1739 pBmp
= &m_bmpDisabled
;
1740 else if ( m_btnState
& wxCONTROL_PRESSED
)
1741 pBmp
= &m_bmpPressed
;
1742 else if ( m_btnState
& wxCONTROL_CURRENT
)
1745 pBmp
= &m_bmpNormal
;
1747 if ( m_blankButtonBg
)
1749 if ( !(flags
& Button_BitmapOnly
) )
1751 wxRendererNative::Get().DrawPushButton(this,
1758 // Draw bitmap centered in drawRect
1759 dc
.DrawBitmap(*pBmp
,
1760 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1761 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1766 void wxComboCtrlBase::RecalcAndRefresh()
1770 wxSizeEvent
evt(GetSize(),GetId());
1771 evt
.SetEventObject(this);
1772 GetEventHandler()->ProcessEvent(evt
);
1777 // ----------------------------------------------------------------------------
1778 // miscellaneous event handlers
1779 // ----------------------------------------------------------------------------
1781 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1783 // Avoid infinite recursion
1784 if ( event
.GetEventObject() == this )
1790 if ( event
.GetEventType() == wxEVT_TEXT
)
1792 if ( m_ignoreEvtText
> 0 )
1799 // For safety, completely re-create a new wxCommandEvent
1800 wxCommandEvent
evt2(event
);
1801 evt2
.SetId(GetId());
1802 evt2
.SetEventObject(this);
1803 HandleWindowEvent(evt2
);
1805 event
.StopPropagation();
1808 // call if cursor is on button area or mouse is captured for the button
1809 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1812 int type
= event
.GetEventType();
1814 if ( type
== wxEVT_MOTION
)
1816 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1817 IsPopupWindowState(Hidden
) )
1819 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1821 // Mouse hover begins
1822 m_btnState
|= wxCONTROL_CURRENT
;
1823 if ( HasCapture() ) // Retain pressed state.
1824 m_btnState
|= wxCONTROL_PRESSED
;
1828 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1831 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1835 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1837 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1839 m_btnState
|= wxCONTROL_PRESSED
;
1842 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1845 // If showing popup now, do not capture mouse or there will be interference
1849 else if ( type
== wxEVT_LEFT_UP
)
1852 // Only accept event if mouse was left-press was previously accepted
1856 if ( m_btnState
& wxCONTROL_PRESSED
)
1858 // If mouse was inside, fire the click event.
1859 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1861 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1865 m_btnState
&= ~(wxCONTROL_PRESSED
);
1869 else if ( type
== wxEVT_LEAVE_WINDOW
)
1871 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1873 m_btnState
&= ~(wxCONTROL_CURRENT
);
1876 if ( IsPopupWindowState(Hidden
) )
1878 m_btnState
&= ~(wxCONTROL_PRESSED
);
1886 // Never have 'hot' state when popup is being shown
1887 // (this is mostly needed because of the animation).
1888 if ( !IsPopupWindowState(Hidden
) )
1889 m_btnState
&= ~wxCONTROL_CURRENT
;
1894 // returns true if event was consumed or filtered
1895 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1896 int WXUNUSED(flags
) )
1898 wxLongLong t
= ::wxGetLocalTimeMillis();
1899 int evtType
= event
.GetEventType();
1901 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1902 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1904 if ( IsPopupWindowState(Visible
) &&
1905 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1913 // Filter out clicks on button immediately after popup dismiss
1914 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1916 event
.SetEventType(0);
1923 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1925 int evtType
= event
.GetEventType();
1927 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1928 (m_windowStyle
& wxCB_READONLY
) )
1930 if ( GetPopupWindowState() >= Animating
)
1932 #if USES_WXPOPUPWINDOW
1933 // Click here always hides the popup.
1934 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1940 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1942 // In read-only mode, clicking the text is the
1943 // same as clicking the button.
1946 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1948 //if ( m_popupInterface->CycleValue() )
1950 if ( m_popupInterface
)
1951 m_popupInterface
->OnComboDoubleClick();
1955 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1957 if ( IsPopupShown() )
1959 // relay (some) mouse events to the popup
1960 m_popup
->GetEventHandler()->ProcessEvent(event
);
1962 else if ( event
.GetWheelAxis() == 0 &&
1963 event
.GetWheelRotation() != 0 &&
1964 event
.GetModifiers() == 0 )
1966 // Translate mousewheel actions into key up/down. This is
1967 // the simplest way of getting native behaviour: scrolling the
1968 // wheel moves selection up/down by one item.
1969 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1970 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1973 GetEventHandler()->ProcessEvent(kevent
);
1986 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1988 if ( IsPopupShown() )
1990 // pass it to the popped up control
1991 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1995 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1997 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1999 if ( mainCtrl
->HandleAsNavigationKey(event
) )
2003 if ( IsKeyPopupToggle(event
) )
2009 int comboStyle
= GetWindowStyle();
2010 wxComboPopup
* popupInterface
= GetPopupControl();
2012 if ( !popupInterface
)
2018 int keycode
= event
.GetKeyCode();
2020 if ( (comboStyle
& wxCB_READONLY
) ||
2021 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
2023 popupInterface
->OnComboKeyEvent(event
);
2030 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
2032 if ( IsPopupShown() )
2034 // pass it to the popped up control
2035 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2039 wxComboPopup
* popupInterface
= GetPopupControl();
2040 if ( popupInterface
)
2042 popupInterface
->OnComboCharEvent(event
);
2051 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
2053 // On Mac, setting focus here leads to infinite recursion and eventually
2054 // a crash due to the SetFocus call producing another event.
2055 // Handle Mac in OnIdleEvent using m_resetFocus.
2057 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2059 if ( GetTextCtrl() && !GetTextCtrl()->HasFocus() )
2062 m_resetFocus
= true;
2064 GetTextCtrl()->SetFocus();
2072 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2076 m_resetFocus
= false;
2077 if ( GetTextCtrl() )
2078 GetTextCtrl()->SetFocus();
2082 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2085 // left margin may also have changed
2086 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2087 m_marginLeft
= GetNativeTextIndent();
2091 // ----------------------------------------------------------------------------
2093 // ----------------------------------------------------------------------------
2095 // Create popup window and the child control
2096 void wxComboCtrlBase::CreatePopup()
2098 wxComboPopup
* popupInterface
= m_popupInterface
;
2103 #ifdef wxComboPopupWindowBase2
2104 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2106 #if !USES_GENERICTLW
2107 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2109 int tlwFlags
= wxNO_BORDER
;
2110 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2111 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2114 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2115 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2116 wxPoint(-21,-21), wxSize(20, 20),
2119 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2120 wxPoint(-21,-21), wxSize(20, 20),
2124 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2127 #endif // wxComboPopupWindowBase2
2129 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2130 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2132 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2133 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2136 popupInterface
->Create(m_winPopup
);
2137 m_popup
= popup
= popupInterface
->GetControl();
2139 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2140 popup
->PushEventHandler( m_popupEvtHandler
);
2142 // This may be helpful on some platforms
2143 // (eg. it bypasses a wxGTK popupwindow bug where
2144 // window is not initially hidden when it should be)
2147 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2150 // Destroy popup window and the child control
2151 void wxComboCtrlBase::DestroyPopup()
2156 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2158 wxDELETE(m_popupEvtHandler
);
2160 if ( m_popupInterface
)
2162 // NB: DestroyPopup() performs 'delete this'.
2163 m_popupInterface
->DestroyPopup();
2164 m_popupInterface
= NULL
;
2169 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2170 wxDELETE(m_popupWinEvtHandler
);
2171 m_winPopup
->Destroy();
2178 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2180 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2184 iface
->InitBase(this);
2187 m_popupInterface
= iface
;
2189 if ( !iface
->LazyCreate() )
2198 // This must be done after creation
2199 if ( !m_valueString
.empty() )
2201 iface
->SetStringValue(m_valueString
);
2206 // Ensures there is atleast the default popup
2207 void wxComboCtrlBase::EnsurePopupControl()
2209 if ( !m_popupInterface
)
2210 SetPopupControl(NULL
);
2213 void wxComboCtrlBase::OnButtonClick()
2215 // Derived classes can override this method for totally custom
2217 switch ( GetPopupWindowState() )
2234 void wxComboCtrlBase::Popup()
2236 wxCommandEvent
event(wxEVT_COMBOBOX_DROPDOWN
, GetId());
2237 event
.SetEventObject(this);
2238 HandleWindowEvent(event
);
2243 void wxComboCtrlBase::ShowPopup()
2245 EnsurePopupControl();
2246 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2248 if ( IsPopupWindowState(Animating
) )
2253 // Space above and below
2259 wxSize ctrlSz
= GetSize();
2261 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2262 scrPos
= GetParent()->ClientToScreen(GetPosition());
2264 spaceAbove
= scrPos
.y
;
2265 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2267 maxHeightPopup
= spaceBelow
;
2268 if ( spaceAbove
> spaceBelow
)
2269 maxHeightPopup
= spaceAbove
;
2272 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2274 if ( widthPopup
< m_widthMinPopup
)
2275 widthPopup
= m_widthMinPopup
;
2277 wxWindow
* winPopup
= m_winPopup
;
2280 // Need to disable tab traversal of parent
2282 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2283 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2284 // that if transient popup is open, then tab traversal is to be ignored.
2285 // However, I think this code would still be needed for cases where
2286 // transient popup doesn't work yet (wxWinCE?).
2287 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2288 wxWindow
* parent
= mainCtrl
->GetParent();
2289 int parentFlags
= parent
->GetWindowStyle();
2290 if ( parentFlags
& wxTAB_TRAVERSAL
)
2292 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2293 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2299 winPopup
= m_winPopup
;
2309 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2311 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2312 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2315 popup
->SetSize(adjustedSize
);
2317 m_popupInterface
->OnPopup();
2320 // Reposition and resize popup window
2323 wxSize szp
= popup
->GetSize();
2326 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2328 // Default anchor is wxLEFT
2329 int anchorSide
= m_anchorSide
;
2331 anchorSide
= wxLEFT
;
2333 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2334 int leftX
= scrPos
.x
- m_extLeft
;
2336 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2339 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2341 // If there is not enough horizontal space, anchor on the other side.
2342 // If there is no space even then, place the popup at x 0.
2343 if ( anchorSide
== wxRIGHT
)
2347 if ( (leftX
+szp
.x
) < screenWidth
)
2348 anchorSide
= wxLEFT
;
2355 if ( (leftX
+szp
.x
) >= screenWidth
)
2358 anchorSide
= wxRIGHT
;
2364 // Select x coordinate according to the anchor side
2365 if ( anchorSide
== wxRIGHT
)
2367 else if ( anchorSide
== wxLEFT
)
2372 int showFlags
= CanDeferShow
;
2374 if ( spaceBelow
< szp
.y
)
2376 popupY
= scrPos
.y
- szp
.y
;
2377 showFlags
|= ShowAbove
;
2380 #if INSTALL_TOPLEV_HANDLER
2381 // Put top level window event handler into place
2382 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2384 if ( !m_toplevEvtHandler
)
2385 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2387 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2389 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2390 toplev
->PushEventHandler( m_toplevEvtHandler
);
2394 // Set string selection (must be this way instead of SetStringSelection)
2397 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2398 m_text
->SelectAll();
2400 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2404 // This is neede since focus/selection indication may change when popup is shown
2408 // This must be after SetStringValue
2409 m_popupWinState
= Animating
;
2411 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2414 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2415 AnimateShow( popupWinRect
, showFlags
) )
2417 DoShowPopup( popupWinRect
, showFlags
);
2421 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2426 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2428 wxWindow
* winPopup
= m_winPopup
;
2430 if ( IsPopupWindowState(Animating
) )
2432 // Make sure the popup window is shown in the right position.
2433 // Should not matter even if animation already did this.
2435 // Some platforms (GTK) may like SetSize and Move to be separate
2436 // (though the bug was probably fixed).
2437 winPopup
->SetSize( rect
);
2439 #if USES_WXPOPUPTRANSIENTWINDOW
2440 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2441 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2446 m_popupWinState
= Visible
;
2448 // If popup window was a generic top-level window, or the
2449 // wxPopupWindow implemenation on this platform is classified as
2450 // perfect, then we should be able to safely set focus to the popup
2452 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2453 m_popup
->SetFocus();
2455 else if ( IsPopupWindowState(Hidden
) )
2457 // Animation was aborted
2459 wxASSERT( !winPopup
->IsShown() );
2461 m_popupWinState
= Hidden
;
2467 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2469 // Just in case, avoid double dismiss
2470 if ( IsPopupWindowState(Hidden
) )
2473 // This must be set before focus - otherwise there will be recursive
2474 // OnPopupDismisses.
2475 m_popupWinState
= Hidden
;
2478 m_winPopup
->Disable();
2480 // Inform popup control itself
2481 m_popupInterface
->OnDismiss();
2483 if ( m_popupEvtHandler
)
2484 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2486 #if INSTALL_TOPLEV_HANDLER
2487 // Remove top level window event handler
2488 if ( m_toplevEvtHandler
)
2490 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2492 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2496 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2498 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2499 m_timeCanAcceptClick
+= 150;
2501 // If cursor not on dropdown button, then clear its state
2502 // (technically not required by all ports, but do it for all just in case)
2503 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2506 // Return parent's tab traversal flag.
2507 // See ShowPopup for notes.
2508 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2510 wxWindow
* parent
= GetParent();
2511 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2512 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2515 // refresh control (necessary even if m_text)
2520 if ( generateEvent
)
2522 wxCommandEvent
event(wxEVT_COMBOBOX_CLOSEUP
, GetId());
2523 event
.SetEventObject(this);
2524 HandleWindowEvent(event
);
2528 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2530 // Should be able to call this without popup interface
2531 if ( IsPopupWindowState(Hidden
) )
2534 // transfer value and show it in textctrl, if any
2535 if ( !IsPopupWindowState(Animating
) )
2536 SetValueByUser( m_popupInterface
->GetStringValue() );
2540 OnPopupDismiss(generateEvent
);
2543 // ----------------------------------------------------------------------------
2544 // customization methods
2545 // ----------------------------------------------------------------------------
2547 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2548 int side
, int spacingX
)
2553 m_btnSpacingX
= spacingX
;
2555 if ( width
> 0 || height
> 0 || spacingX
)
2556 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2561 wxSize
wxComboCtrlBase::GetButtonSize()
2563 if ( m_btnSize
.x
> 0 )
2566 wxSize
retSize(m_btnWid
,m_btnHei
);
2568 // Need to call CalculateAreas now if button size is
2569 // is not explicitly specified.
2570 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2574 retSize
= m_btnSize
;
2580 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2582 const wxBitmap
& bmpPressed
,
2583 const wxBitmap
& bmpHover
,
2584 const wxBitmap
& bmpDisabled
)
2586 m_bmpNormal
= bmpNormal
;
2587 m_blankButtonBg
= blankButtonBg
;
2589 if ( bmpPressed
.IsOk() )
2590 m_bmpPressed
= bmpPressed
;
2592 m_bmpPressed
= bmpNormal
;
2594 if ( bmpHover
.IsOk() )
2595 m_bmpHover
= bmpHover
;
2597 m_bmpHover
= bmpNormal
;
2599 if ( bmpDisabled
.IsOk() )
2600 m_bmpDisabled
= bmpDisabled
;
2602 m_bmpDisabled
= bmpNormal
;
2607 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2611 // move textctrl accordingly
2612 wxRect r
= m_text
->GetRect();
2613 int inc
= width
- m_widthCustomPaint
;
2616 m_text
->SetSize( r
);
2619 m_widthCustomPaint
= width
;
2624 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2626 // For general sanity's sake, we ignore top margin. Instead
2627 // we will always try to center the text vertically.
2630 if ( margins
.x
!= -1 )
2632 m_marginLeft
= margins
.x
;
2633 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2637 m_marginLeft
= GetNativeTextIndent();
2638 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2641 if ( margins
.y
!= -1 )
2651 wxPoint
wxComboCtrlBase::DoGetMargins() const
2653 return wxPoint(m_marginLeft
, -1);
2656 #if WXWIN_COMPATIBILITY_2_8
2657 void wxComboCtrlBase::SetTextIndent( int indent
)
2661 m_marginLeft
= GetNativeTextIndent();
2662 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2666 m_marginLeft
= indent
;
2667 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2673 wxCoord
wxComboCtrlBase::GetTextIndent() const
2675 return m_marginLeft
;
2679 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2681 return DEFAULT_TEXT_INDENT
;
2684 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2686 m_textCtrlStyle
= style
;
2689 m_text
->SetWindowStyle(style
);
2692 // ----------------------------------------------------------------------------
2693 // wxTextEntry interface
2694 // ----------------------------------------------------------------------------
2696 wxString
wxComboCtrlBase::DoGetValue() const
2699 return m_text
->GetValue();
2700 return m_valueString
;
2703 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2706 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2709 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2711 // Note: before wxComboCtrl inherited from wxTextEntry,
2712 // this code used to be in SetValueWithEvent().
2714 // Since wxComboPopup may want to paint the combo as well, we need
2715 // to set the string value here (as well as sometimes in ShowPopup).
2716 if ( m_valueString
!= value
)
2719 wxString trueValue
= value
;
2721 // Conform to wxComboBox behaviour: read-only control can only accept
2722 // valid list items and empty string
2723 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2725 found
= m_popupInterface
->FindItem(value
,
2731 m_valueString
= trueValue
;
2733 EnsurePopupControl();
2735 if ( m_popupInterface
)
2736 m_popupInterface
->SetStringValue(trueValue
);
2743 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2745 // NB: Order of function calls is important here. Otherwise
2746 // the SelectAll() may not work.
2750 m_text
->SetValue(value
);
2752 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2753 m_text
->SelectAll();
2759 // In this SetValue variant wxComboPopup::SetStringValue is not called
2760 void wxComboCtrlBase::SetText(const wxString
& value
)
2762 // Unlike in SetValue(), this must be called here or
2763 // the behaviour will no be consistent in readonlys.
2764 EnsurePopupControl();
2766 m_valueString
= value
;
2771 m_text
->SetValue( value
);
2777 void wxComboCtrlBase::Copy()
2783 void wxComboCtrlBase::Cut()
2789 void wxComboCtrlBase::Paste()
2795 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2798 m_text
->SetInsertionPoint(pos
);
2801 long wxComboCtrlBase::GetInsertionPoint() const
2804 return m_text
->GetInsertionPoint();
2809 long wxComboCtrlBase::GetLastPosition() const
2812 return m_text
->GetLastPosition();
2817 void wxComboCtrlBase::WriteText(const wxString
& text
)
2821 m_text
->WriteText(text
);
2822 OnSetValue(m_text
->GetValue());
2830 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2834 if ( flags
& SetValue_SendEvent
)
2835 m_text
->SetValue(value
);
2837 m_text
->ChangeValue(value
);
2843 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2847 m_text
->Replace(from
, to
, value
);
2848 OnSetValue(m_text
->GetValue());
2852 void wxComboCtrlBase::Remove(long from
, long to
)
2856 m_text
->Remove(from
, to
);
2857 OnSetValue(m_text
->GetValue());
2861 void wxComboCtrlBase::SetSelection(long from
, long to
)
2864 m_text
->SetSelection(from
, to
);
2867 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2871 m_text
->GetSelection(from
, to
);
2880 bool wxComboCtrlBase::IsEditable() const
2883 return m_text
->IsEditable();
2887 void wxComboCtrlBase::SetEditable(bool editable
)
2890 m_text
->SetEditable(editable
);
2893 void wxComboCtrlBase::Undo()
2899 void wxComboCtrlBase::Redo()
2905 bool wxComboCtrlBase::CanUndo() const
2908 return m_text
->CanUndo();
2913 bool wxComboCtrlBase::CanRedo() const
2916 return m_text
->CanRedo();
2921 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2926 res
= m_text
->SetHint(hint
);
2931 wxString
wxComboCtrlBase::GetHint() const
2936 #endif // wxUSE_COMBOCTRL