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"
29 #include "wx/combobox.h"
30 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr
[] = "comboBox";
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 wxDEFINE_FLAGS( wxComboBoxStyle
)
37 wxBEGIN_FLAGS( wxComboBoxStyle
)
38 // new style border flags, we put them first to
39 // use them for streaming out
40 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
41 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
42 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
43 wxFLAGS_MEMBER(wxBORDER_RAISED
)
44 wxFLAGS_MEMBER(wxBORDER_STATIC
)
45 wxFLAGS_MEMBER(wxBORDER_NONE
)
47 // old style border flags
48 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
49 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
50 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
51 wxFLAGS_MEMBER(wxRAISED_BORDER
)
52 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
53 wxFLAGS_MEMBER(wxBORDER
)
55 // standard window styles
56 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
57 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
58 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
59 wxFLAGS_MEMBER(wxWANTS_CHARS
)
60 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
61 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
62 wxFLAGS_MEMBER(wxVSCROLL
)
63 wxFLAGS_MEMBER(wxHSCROLL
)
65 wxFLAGS_MEMBER(wxCB_SIMPLE
)
66 wxFLAGS_MEMBER(wxCB_SORT
)
67 wxFLAGS_MEMBER(wxCB_READONLY
)
68 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
70 wxEND_FLAGS( wxComboBoxStyle
)
72 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
74 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
75 wxEVENT_PROPERTY( Select
, wxEVT_COMBOBOX
, wxCommandEvent
)
76 wxEVENT_PROPERTY( TextEnter
, wxEVT_TEXT_ENTER
, wxCommandEvent
)
79 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
80 0 /*flags*/, wxT("Helpstring"), wxT("group"))
81 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
82 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
83 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
84 0 /*flags*/, wxT("Helpstring"), wxT("group"))
85 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
86 0 /*flags*/, wxT("Helpstring"), wxT("group"))
88 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
89 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
90 wxT("Helpstring"), wxT("group")) // style
91 wxEND_PROPERTIES_TABLE()
93 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
95 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
96 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
98 #endif // wxUSE_COMBOBOX
105 #include "wx/dcclient.h"
106 #include "wx/settings.h"
107 #include "wx/timer.h"
108 #include "wx/textctrl.h"
111 #include "wx/tooltip.h"
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();
392 if ( !winFocused
|| (
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
403 m_combo
->HidePopup(true);
409 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
411 m_combo
->HidePopup(true);
415 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
417 m_combo
->HidePopup(true);
421 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
423 m_combo
->HidePopup(true);
427 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
429 m_combo
->HidePopup(true);
433 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
435 m_combo
->HidePopup(true);
439 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
441 m_combo
->HidePopup(true);
445 #endif // INSTALL_TOPLEV_HANDLER
447 // ----------------------------------------------------------------------------
448 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
450 // ----------------------------------------------------------------------------
452 class wxComboPopupWindow
: public wxComboPopupWindowBase
456 wxComboPopupWindow( wxComboCtrlBase
*parent
,
458 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
459 : wxComboPopupWindowBase(parent
,style
)
461 : wxComboPopupWindowBase(parent
,
472 #if USES_WXPOPUPTRANSIENTWINDOW
473 virtual bool Show( bool show
);
474 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
476 virtual void OnDismiss();
484 #if USES_WXPOPUPTRANSIENTWINDOW
485 bool wxComboPopupWindow::Show( bool show
)
487 // Guard against recursion
489 return wxComboPopupWindowBase::Show(show
);
493 wxPopupTransientWindow
* const
494 ptw
= static_cast<wxPopupTransientWindow
*>(this);
496 if ( show
!= ptw
->IsShown() )
499 // We used to do wxPopupTransientWindow::Popup here,
500 // but this would hide normal Show, which we are
501 // also going to need.
512 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
514 return wxPopupTransientWindow::ProcessLeftDown(event
);
517 // First thing that happens when a transient popup closes is that this method gets called.
518 void wxComboPopupWindow::OnDismiss()
520 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
521 wxASSERT_MSG( wxDynamicCast(combo
, wxComboCtrlBase
),
522 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
524 combo
->OnPopupDismiss(true);
526 #endif // USES_WXPOPUPTRANSIENTWINDOW
529 // ----------------------------------------------------------------------------
530 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
531 // of a popup window. It is separate so we can have different types
533 // ----------------------------------------------------------------------------
535 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
539 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
544 void OnSizeEvent( wxSizeEvent
& event
);
545 void OnKeyEvent(wxKeyEvent
& event
);
547 void OnActivate( wxActivateEvent
& event
);
551 wxComboCtrlBase
* m_combo
;
553 DECLARE_EVENT_TABLE()
557 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
558 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
559 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
560 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
562 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
564 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
568 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
570 // Block the event so that the popup control does not get auto-resized.
573 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
575 // Relay keyboard event to the main child controls
576 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
577 wxWindowList::iterator node
= children
.begin();
578 wxWindow
* child
= (wxWindow
*)*node
;
579 child
->GetEventHandler()->ProcessEvent(event
);
583 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
585 if ( !event
.GetActive() )
587 // Tell combo control that we are dismissed.
588 m_combo
->HidePopup(true);
596 // ----------------------------------------------------------------------------
599 // ----------------------------------------------------------------------------
601 wxComboPopup::~wxComboPopup()
605 void wxComboPopup::OnPopup()
609 void wxComboPopup::OnDismiss()
613 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
615 return wxStaticCast(m_combo
, wxComboCtrl
);
618 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
620 int WXUNUSED(maxHeight
) )
622 return wxSize(minWidth
,prefHeight
);
625 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
626 wxDC
& dc
, const wxRect
& rect
)
628 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
630 combo
->PrepareBackground(dc
,rect
,0);
632 dc
.DrawText( combo
->GetValue(),
633 rect
.x
+ combo
->m_marginLeft
,
634 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
638 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
640 DefaultPaintComboControl(m_combo
,dc
,rect
);
643 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
648 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
653 void wxComboPopup::OnComboDoubleClick()
657 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
661 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
662 wxString
* WXUNUSED(trueItem
))
667 bool wxComboPopup::LazyCreate()
672 void wxComboPopup::Dismiss()
674 m_combo
->HidePopup(true);
677 void wxComboPopup::DestroyPopup()
679 // Here we make sure that the popup control's Destroy() gets called.
680 // This is necessary for the wxPersistentWindow to work properly.
681 wxWindow
* popupCtrl
= GetControl();
684 // While all wxComboCtrl examples have m_popupInterface and
685 // popupCtrl as the same class (that will be deleted via the
686 // Destroy() call below), it is technically still possible to
687 // have implementations where they are in fact not same
688 // multiple-inherited class. Here we use C++ RTTI to check for
691 // It is probably better to delete m_popupInterface first, so
692 // that it retains access to its popup control window.
693 if ( dynamic_cast<void*>(this) !=
694 dynamic_cast<void*>(popupCtrl
) )
697 popupCtrl
->Destroy();
705 // ----------------------------------------------------------------------------
707 // ----------------------------------------------------------------------------
710 // This is pushed to the event handler queue of the child textctrl.
712 class wxComboBoxExtraInputHandler
: public wxEvtHandler
716 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
721 virtual ~wxComboBoxExtraInputHandler() { }
722 void OnKey(wxKeyEvent
& event
);
723 void OnFocus(wxFocusEvent
& event
);
726 wxComboCtrlBase
* m_combo
;
729 DECLARE_EVENT_TABLE()
733 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
734 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
735 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
736 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
737 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
738 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
742 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
744 // Let the wxComboCtrl event handler have a go first.
745 wxComboCtrlBase
* combo
= m_combo
;
747 wxKeyEvent
redirectedEvent(event
);
748 redirectedEvent
.SetId(combo
->GetId());
749 redirectedEvent
.SetEventObject(combo
);
751 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
753 // Don't let TAB through to the text ctrl - looks ugly
754 if ( event
.GetKeyCode() != WXK_TAB
)
759 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
761 // FIXME: This code does run when control is clicked,
762 // yet on Windows it doesn't select all the text.
763 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
764 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
766 if ( m_combo
->GetTextCtrl() )
767 m_combo
->GetTextCtrl()->SelectAll();
769 m_combo
->SelectAll();
772 // Send focus indication to parent.
773 // NB: This is needed for cases where the textctrl gets focus
774 // instead of its parent. While this may trigger multiple
775 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
776 // from combo's focus event handler), they should be quite
778 wxFocusEvent
evt2(event
);
779 evt2
.SetId(m_combo
->GetId());
780 evt2
.SetEventObject(m_combo
);
781 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
788 // This is pushed to the event handler queue of the control in popup.
791 class wxComboPopupEvtHandler
: public wxEvtHandler
795 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
799 m_beenInside
= false;
801 // Let's make it so that the popup control will not receive mouse
802 // events until mouse left button has been up.
803 m_blockEventsToPopup
= true;
805 virtual ~wxComboPopupEvtHandler() { }
807 void OnMouseEvent( wxMouseEvent
& event
);
809 // Called from wxComboCtrlBase::OnPopupDismiss
810 void OnPopupDismiss()
812 m_beenInside
= false;
813 m_blockEventsToPopup
= true;
817 wxComboCtrlBase
* m_combo
;
820 bool m_blockEventsToPopup
;
823 DECLARE_EVENT_TABLE()
827 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
828 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
832 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
834 wxPoint pt
= event
.GetPosition();
835 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
836 int evtType
= event
.GetEventType();
837 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
838 bool relayToButton
= false;
842 if ( !isInside
|| !m_combo
->IsPopupShown() )
844 // Mouse is outside the popup or popup is not actually shown (yet)
846 if ( evtType
== wxEVT_MOTION
||
847 evtType
== wxEVT_LEFT_DOWN
||
848 evtType
== wxEVT_LEFT_UP
||
849 evtType
== wxEVT_RIGHT_DOWN
)
851 // Block motion and click events outside the popup
857 // Mouse is inside the popup, which is fully shown
861 // Do not let the popup control respond to mouse events until
862 // mouse press used to display the popup has been lifted. This
863 // is important for users with slower mouse fingers or mouse
864 // drivers. Note that we have some redundancy here, just in
865 // case the popup is some native control that does not emit all
866 // mouse event types.
867 if ( evtType
== wxEVT_MOTION
)
869 if ( m_blockEventsToPopup
)
871 if ( event
.LeftIsDown() )
874 m_blockEventsToPopup
= false;
877 else if ( evtType
== wxEVT_LEFT_DOWN
)
879 if ( m_blockEventsToPopup
)
880 m_blockEventsToPopup
= false;
882 else if ( evtType
== wxEVT_LEFT_UP
)
884 if ( m_blockEventsToPopup
)
886 // On first left up, stop blocking mouse events (but still
888 m_blockEventsToPopup
= false;
891 // Also, this button press was (probably) used to display
892 // the popup, so relay it back to the drop-down button
893 // (which supposedly originated it). This is necessary to
894 // refresh it properly.
895 relayToButton
= true;
898 else if ( m_blockEventsToPopup
)
905 // Some mouse events to popup that happen outside it, before cursor
906 // has been inside the popup, need to be ignored by it but relayed to
909 if ( evtType
== wxEVT_LEFT_UP
)
911 if ( !m_combo
->IsPopupShown() )
914 relayToButton
= true;
916 else if ( !isInside
&& !m_beenInside
)
918 // Popup is shown but the cursor is not inside, nor it has been
919 relayToButton
= true;
925 wxWindow
* btn
= m_combo
->GetButton();
927 btn
->GetEventHandler()->ProcessEvent(event
);
929 // Bypass the event handling mechanism. Using it would be
930 // confusing for the platform-specific wxComboCtrl
932 m_combo
->HandleButtonMouseEvent(event
, 0);
936 // ----------------------------------------------------------------------------
937 // wxComboCtrlTextCtrl
938 // ----------------------------------------------------------------------------
940 class wxComboCtrlTextCtrl
: public wxTextCtrl
943 wxComboCtrlTextCtrl() : wxTextCtrl() { }
944 virtual ~wxComboCtrlTextCtrl() { }
946 virtual wxWindow
*GetMainWindowOfCompositeControl()
948 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
950 // Returning this instead of just 'parent' lets FindFocus work
951 // correctly even when parent control is a child of a composite
952 // generic control (as is case with wxGenericDatePickerCtrl).
953 return combo
->GetMainWindowOfCompositeControl();
957 // ----------------------------------------------------------------------------
959 // ----------------------------------------------------------------------------
962 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
963 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
964 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
965 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
966 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
967 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
968 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
969 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
970 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
974 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
976 void wxComboCtrlBase::Init()
980 m_popupWinState
= Hidden
;
983 m_popupInterface
= NULL
;
985 m_popupEvtHandler
= NULL
;
986 m_textEvtHandler
= NULL
;
988 #if INSTALL_TOPLEV_HANDLER
989 m_toplevEvtHandler
= NULL
;
992 m_mainCtrlWnd
= this;
995 m_widthMinPopup
= -1;
997 m_widthCustomPaint
= 0;
998 m_widthCustomBorder
= 0;
1001 m_btnWidDefault
= 0;
1002 m_blankButtonBg
= false;
1003 m_ignoreEvtText
= 0;
1004 m_popupWinType
= POPUPWIN_NONE
;
1005 m_btnWid
= m_btnHei
= -1;
1006 m_btnSide
= wxRIGHT
;
1013 m_textCtrlStyle
= 0;
1014 m_timeCanAcceptClick
= 0;
1016 m_resetFocus
= false;
1017 m_hasTcBgCol
= false;
1020 bool wxComboCtrlBase::Create(wxWindow
*parent
,
1022 const wxString
& value
,
1026 const wxValidator
& validator
,
1027 const wxString
& name
)
1029 if ( !wxControl::Create(parent
,
1033 style
| wxWANTS_CHARS
,
1038 m_valueString
= value
;
1042 m_marginLeft
= GetNativeTextIndent();
1044 m_iFlags
|= wxCC_IFLAG_CREATED
;
1046 // If x and y indicate valid size, wxSizeEvent won't be
1047 // emitted automatically, so we need to add artificial one.
1048 if ( size
.x
> 0 && size
.y
> 0 )
1050 wxSizeEvent
evt(size
,GetId());
1051 evt
.SetEventObject(this);
1052 GetEventHandler()->AddPendingEvent(evt
);
1058 void wxComboCtrlBase::InstallInputHandlers()
1062 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1063 m_text
->PushEventHandler(m_textEvtHandler
);
1068 wxComboCtrlBase::CreateTextCtrl(int style
)
1070 if ( !(m_windowStyle
& wxCB_READONLY
) )
1075 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1076 // not used by the wxPropertyGrid and therefore the tab is processed by
1077 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1078 // navigation event is then sent to the wrong window.
1079 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1081 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1082 style
|= wxTE_PROCESS_ENTER
;
1084 // Ignore EVT_TEXT generated by the constructor (but only
1085 // if the event redirector already exists)
1086 // NB: This must be " = 1" instead of "++";
1087 if ( m_textEvtHandler
)
1088 m_ignoreEvtText
= 1;
1090 m_ignoreEvtText
= 0;
1092 m_text
= new wxComboCtrlTextCtrl();
1093 m_text
->Create(this, wxID_ANY
, m_valueString
,
1094 wxDefaultPosition
, wxSize(10,-1),
1097 // Connecting the events is currently the most reliable way
1098 wxWindowID id
= m_text
->GetId();
1099 m_text
->Connect(id
, wxEVT_TEXT
,
1100 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1102 m_text
->Connect(id
, wxEVT_TEXT_ENTER
,
1103 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1106 m_text
->SetHint(m_hintText
);
1110 void wxComboCtrlBase::OnThemeChange()
1112 // Because wxComboCtrl has transparent parts on most platforms, we
1113 // don't want to touch the actual background colour. Instead, we just
1114 // usually re-obtain m_tcBgCol here.
1116 #if defined(__WXMSW__) || defined(__WXGTK__)
1117 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1119 wxVisualAttributes vattrs
;
1120 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1121 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1124 if ( !m_hasTcBgCol
)
1125 m_tcBgCol
= vattrs
.colBg
;
1128 // Only change the colours if application has not specified
1132 SetOwnForegroundColour(vattrs
.colFg
);
1134 if ( !HasTransparentBackground() )
1136 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1138 #endif // !__WXMAC__
1141 wxComboCtrlBase::~wxComboCtrlBase()
1146 #if INSTALL_TOPLEV_HANDLER
1147 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1148 m_toplevEvtHandler
= NULL
;
1154 m_text
->RemoveEventHandler(m_textEvtHandler
);
1156 delete m_textEvtHandler
;
1160 // ----------------------------------------------------------------------------
1162 // ----------------------------------------------------------------------------
1164 // Recalculates button and textctrl areas
1165 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1167 wxSize sz
= GetClientSize();
1168 int customBorder
= m_widthCustomBorder
;
1169 int btnBorder
; // border for button only
1171 // check if button should really be outside the border: we'll do it it if
1172 // its platform default or bitmap+pushbutton background is used, but not if
1173 // there is vertical size adjustment or horizontal spacing.
1174 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1175 (m_bmpNormal
.IsOk() && m_blankButtonBg
) ) &&
1176 m_btnSpacingX
== 0 &&
1179 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1182 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1183 m_btnSpacingX
== 0 && !m_bmpNormal
.IsOk() )
1185 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1190 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1191 btnBorder
= customBorder
;
1194 // Defaul indentation
1195 if ( m_marginLeft
< 0 )
1196 m_marginLeft
= GetNativeTextIndent();
1198 int butWidth
= btnWidth
;
1200 if ( butWidth
<= 0 )
1201 butWidth
= m_btnWidDefault
;
1203 m_btnWidDefault
= butWidth
;
1205 if ( butWidth
<= 0 )
1208 int butHeight
= sz
.y
- btnBorder
*2;
1210 // Adjust button width
1212 butWidth
= m_btnWid
;
1215 // Adjust button width to match aspect ratio
1216 // (but only if control is smaller than best size).
1217 int bestHeight
= GetBestSize().y
;
1218 int height
= GetSize().y
;
1220 if ( height
< bestHeight
)
1222 // Make very small buttons square, as it makes
1223 // them accommodate arrow image better and still
1226 butWidth
= (height
*butWidth
)/bestHeight
;
1228 butWidth
= butHeight
;
1232 // Adjust button height
1234 butHeight
= m_btnHei
;
1236 // Use size of normal bitmap if...
1239 // button width is set to default and blank button bg is not drawn
1240 if ( m_bmpNormal
.IsOk() )
1242 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1243 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1245 // If drawing blank button background, we need to add some margin.
1246 if ( m_blankButtonBg
)
1248 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1249 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1252 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1253 butWidth
= bmpReqWidth
;
1254 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1255 butHeight
= bmpReqHeight
;
1257 // Need to fix height?
1258 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1260 int newY
= butHeight
+(customBorder
*2);
1261 SetClientSize(wxDefaultCoord
,newY
);
1262 if ( m_bmpNormal
.IsOk() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1263 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1265 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1271 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1273 m_btnSize
.x
= butWidth
;
1274 m_btnSize
.y
= butHeight
;
1276 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1277 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1278 m_btnArea
.width
= butAreaWid
;
1279 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1281 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1282 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1283 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1284 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1289 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1290 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1295 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1300 wxSize sz
= GetClientSize();
1302 int customBorder
= m_widthCustomBorder
;
1303 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1307 if ( !m_widthCustomPaint
)
1309 // No special custom paint area - we can use 0 left margin
1311 if ( m_text
->SetMargins(0) )
1312 textCtrlXAdjust
= 0;
1313 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1317 // There is special custom paint area - it is better to
1318 // use some margin with the wxTextCtrl.
1319 m_text
->SetMargins(m_marginLeft
);
1320 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1321 m_marginLeft
+ textCtrlXAdjust
;
1324 // Centre textctrl vertically, if needed
1325 #if !TEXTCTRL_TEXT_CENTERED
1326 int tcSizeY
= m_text
->GetBestSize().y
;
1327 int diff0
= sz
.y
- tcSizeY
;
1328 int y
= textCtrlYAdjust
+ (diff0
/2);
1330 wxUnusedVar(textCtrlYAdjust
);
1334 if ( y
< customBorder
)
1339 m_tcArea
.width
- m_tcArea
.x
- x
,
1342 // Make sure textctrl doesn't exceed the bottom custom border
1343 wxSize tsz
= m_text
->GetSize();
1344 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1347 tsz
.y
= tsz
.y
- diff1
- 1;
1348 m_text
->SetSize(tsz
);
1353 // If it has border, have textctrl fill the entire text field.
1354 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1356 m_tcArea
.width
- m_widthCustomPaint
,
1361 wxSize
wxComboCtrlBase::DoGetBestSize() const
1363 int width
= m_text
? m_text
->GetBestSize().x
: 80;
1365 return GetSizeFromTextSize(width
);
1368 wxSize
wxComboCtrlBase::DoGetSizeFromTextSize(int xlen
, int ylen
) const
1370 // Calculate close-to-native control height
1374 #if wxUSE_COMBOBOX && (defined(__WXMSW__) || defined(__WXGTK__)) \
1375 && !defined(__WXUNIVERSAL__)
1376 wxComboBox
* cb
= new wxComboBox
;
1378 cb
->Create(const_cast<wxComboCtrlBase
*>(this), wxID_ANY
);
1379 if ( m_font
.IsOk() )
1380 cb
->SetFont(m_font
);
1381 fhei
= cb
->GetBestSize().y
;
1384 if ( m_font
.IsOk() )
1385 fhei
= (m_font
.GetPointSize()*2) + 5;
1386 else if ( wxNORMAL_FONT
->IsOk() )
1387 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1390 #endif // only for wxComboBox on MSW or GTK
1392 // Need to force height to accommodate bitmap?
1393 int btnSizeY
= m_btnSize
.y
;
1394 if ( m_bmpNormal
.IsOk() && fhei
< btnSizeY
)
1397 // Control height doesn't depend on border
1400 int border = m_windowStyle & wxBORDER_MASK;
1401 if ( border == wxSIMPLE_BORDER )
1403 else if ( border == wxNO_BORDER )
1404 fhei += (m_widthCustomBorder*2);
1411 // these are the numbers from the HIG:
1412 switch ( m_windowVariant
)
1414 case wxWINDOW_VARIANT_NORMAL
:
1418 case wxWINDOW_VARIANT_SMALL
:
1421 case wxWINDOW_VARIANT_MINI
:
1427 fhei
+= 2 * FOCUS_RING
;
1430 int fwid
= xlen
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1432 // Add the margins we have previously set
1433 wxPoint
marg( GetMargins() );
1434 fwid
+= wxMax(0, marg
.x
);
1435 fhei
+= wxMax(0, marg
.y
);
1438 fhei
+= ylen
- GetCharHeight();
1440 return wxSize(fwid
, fhei
);
1443 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1448 // defined by actual wxComboCtrls
1454 // ----------------------------------------------------------------------------
1455 // standard operations
1456 // ----------------------------------------------------------------------------
1458 bool wxComboCtrlBase::Enable(bool enable
)
1460 if ( !wxControl::Enable(enable
) )
1464 m_btn
->Enable(enable
);
1466 m_text
->Enable(enable
);
1473 bool wxComboCtrlBase::Show(bool show
)
1475 if ( !wxControl::Show(show
) )
1487 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1489 if ( !wxControl::SetFont(font
) )
1494 // Without hiding the wxTextCtrl there would be some
1495 // visible 'flicker' (at least on Windows XP).
1497 m_text
->SetFont(font
);
1506 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1508 wxControl::DoSetToolTip(tooltip
);
1510 // Set tool tip for button and text box
1513 const wxString
&tip
= tooltip
->GetTip();
1514 if ( m_text
) m_text
->SetToolTip(tip
);
1515 if ( m_btn
) m_btn
->SetToolTip(tip
);
1519 if ( m_text
) m_text
->SetToolTip( NULL
);
1520 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1523 #endif // wxUSE_TOOLTIPS
1525 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1527 if ( wxControl::SetForegroundColour(colour
) )
1530 m_text
->SetForegroundColour(colour
);
1536 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1539 m_text
->SetBackgroundColour(colour
);
1541 m_hasTcBgCol
= true;
1545 wxColour
wxComboCtrlBase::GetBackgroundColour() const
1548 return m_text
->GetBackgroundColour();
1552 // ----------------------------------------------------------------------------
1554 // ----------------------------------------------------------------------------
1556 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1557 // prepare combo box background on area in a way typical on platform
1558 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1560 wxSize sz
= GetClientSize();
1562 bool doDrawFocusRect
; // also selected
1564 // For smaller size control (and for disabled background) use less spacing
1568 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1571 isEnabled
= IsEnabled();
1572 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1574 // Windows-style: for smaller size control (and for disabled background) use less spacing
1575 focusSpacingX
= isEnabled
? 2 : 1;
1576 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1580 // Drawing a list item
1581 isEnabled
= true; // they are never disabled
1582 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1588 // Set the background sub-rectangle for selection, disabled etc
1589 wxRect
selRect(rect
);
1590 selRect
.y
+= focusSpacingY
;
1591 selRect
.height
-= (focusSpacingY
*2);
1595 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1596 wcp
+= m_widthCustomPaint
;
1598 selRect
.x
+= wcp
+ focusSpacingX
;
1599 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1604 bool doDrawSelRect
= true;
1606 // Determine foreground colour
1609 if ( doDrawFocusRect
)
1611 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1613 else if ( m_hasFgCol
)
1615 // Honour the custom foreground colour
1616 fgCol
= GetForegroundColour();
1620 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1625 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1628 // Determine background colour
1631 if ( doDrawFocusRect
)
1633 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1635 else if ( m_hasTcBgCol
)
1637 // Honour the custom background colour
1642 #ifndef __WXMAC__ // see note in OnThemeChange
1643 doDrawSelRect
= false;
1644 bgCol
= GetBackgroundColour();
1646 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1652 #ifndef __WXMAC__ // see note in OnThemeChange
1653 bgCol
= GetBackgroundColour();
1655 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1659 dc
.SetTextForeground( fgCol
);
1660 dc
.SetBrush( bgCol
);
1661 if ( doDrawSelRect
)
1664 dc
.DrawRectangle( selRect
);
1667 // Don't clip exactly to the selection rectangle so we can draw
1668 // to the non-selected area in front of it.
1669 wxRect
clipRect(rect
.x
,rect
.y
,
1670 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1671 dc
.SetClippingRegion(clipRect
);
1674 // Save the library size a bit for platforms that re-implement this.
1675 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1680 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1682 int drawState
= m_btnState
;
1684 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1685 GetPopupWindowState() >= Animating
)
1686 drawState
|= wxCONTROL_PRESSED
;
1688 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1689 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1693 // Make sure area is not larger than the control
1694 if ( drawRect
.y
< rect
.y
)
1695 drawRect
.y
= rect
.y
;
1696 if ( drawRect
.height
> rect
.height
)
1697 drawRect
.height
= rect
.height
;
1699 bool enabled
= IsEnabled();
1702 drawState
|= wxCONTROL_DISABLED
;
1704 // Need to clear button background even if m_btn is present
1705 // and also when using custom bitmap for the button
1706 if ( (flags
& Button_PaintBackground
) &&
1707 (!HasTransparentBackground() ||
1708 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1712 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1713 bgCol
= GetParent()->GetBackgroundColour();
1715 bgCol
= GetBackgroundColour();
1719 dc
.DrawRectangle(rect
);
1722 if ( !m_bmpNormal
.IsOk() )
1724 if ( flags
& Button_BitmapOnly
)
1727 // Draw standard button
1728 wxRendererNative::Get().DrawComboBoxDropButton(this,
1740 pBmp
= &m_bmpDisabled
;
1741 else if ( m_btnState
& wxCONTROL_PRESSED
)
1742 pBmp
= &m_bmpPressed
;
1743 else if ( m_btnState
& wxCONTROL_CURRENT
)
1746 pBmp
= &m_bmpNormal
;
1748 if ( m_blankButtonBg
)
1750 if ( !(flags
& Button_BitmapOnly
) )
1752 wxRendererNative::Get().DrawPushButton(this,
1759 // Draw bitmap centered in drawRect
1760 dc
.DrawBitmap(*pBmp
,
1761 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1762 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1767 void wxComboCtrlBase::RecalcAndRefresh()
1771 wxSizeEvent
evt(GetSize(),GetId());
1772 evt
.SetEventObject(this);
1773 GetEventHandler()->ProcessEvent(evt
);
1778 // ----------------------------------------------------------------------------
1779 // miscellaneous event handlers
1780 // ----------------------------------------------------------------------------
1782 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1784 // Avoid infinite recursion
1785 if ( event
.GetEventObject() == this )
1791 if ( event
.GetEventType() == wxEVT_TEXT
)
1793 if ( m_ignoreEvtText
> 0 )
1800 // For safety, completely re-create a new wxCommandEvent
1801 wxCommandEvent
evt2(event
);
1802 evt2
.SetId(GetId());
1803 evt2
.SetEventObject(this);
1804 HandleWindowEvent(evt2
);
1806 event
.StopPropagation();
1809 // call if cursor is on button area or mouse is captured for the button
1810 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1813 int type
= event
.GetEventType();
1815 if ( type
== wxEVT_MOTION
)
1817 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1818 IsPopupWindowState(Hidden
) )
1820 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1822 // Mouse hover begins
1823 m_btnState
|= wxCONTROL_CURRENT
;
1824 if ( HasCapture() ) // Retain pressed state.
1825 m_btnState
|= wxCONTROL_PRESSED
;
1829 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1832 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1836 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1838 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1840 m_btnState
|= wxCONTROL_PRESSED
;
1843 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1846 // If showing popup now, do not capture mouse or there will be interference
1850 else if ( type
== wxEVT_LEFT_UP
)
1853 // Only accept event if mouse was left-press was previously accepted
1857 if ( m_btnState
& wxCONTROL_PRESSED
)
1859 // If mouse was inside, fire the click event.
1860 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1862 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1866 m_btnState
&= ~(wxCONTROL_PRESSED
);
1870 else if ( type
== wxEVT_LEAVE_WINDOW
)
1872 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1874 m_btnState
&= ~(wxCONTROL_CURRENT
);
1877 if ( IsPopupWindowState(Hidden
) )
1879 m_btnState
&= ~(wxCONTROL_PRESSED
);
1887 // Never have 'hot' state when popup is being shown
1888 // (this is mostly needed because of the animation).
1889 if ( !IsPopupWindowState(Hidden
) )
1890 m_btnState
&= ~wxCONTROL_CURRENT
;
1895 // returns true if event was consumed or filtered
1896 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1897 int WXUNUSED(flags
) )
1899 wxLongLong t
= ::wxGetLocalTimeMillis();
1900 int evtType
= event
.GetEventType();
1902 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1903 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1905 if ( IsPopupWindowState(Visible
) &&
1906 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1914 // Filter out clicks on button immediately after popup dismiss
1915 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1917 event
.SetEventType(0);
1924 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1926 int evtType
= event
.GetEventType();
1928 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1929 (m_windowStyle
& wxCB_READONLY
) )
1931 if ( GetPopupWindowState() >= Animating
)
1933 #if USES_WXPOPUPWINDOW
1934 // Click here always hides the popup.
1935 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1941 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1943 // In read-only mode, clicking the text is the
1944 // same as clicking the button.
1947 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1949 //if ( m_popupInterface->CycleValue() )
1951 if ( m_popupInterface
)
1952 m_popupInterface
->OnComboDoubleClick();
1956 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1958 if ( IsPopupShown() )
1960 // relay (some) mouse events to the popup
1961 m_popup
->GetEventHandler()->ProcessEvent(event
);
1963 else if ( event
.GetWheelAxis() == 0 &&
1964 event
.GetWheelRotation() != 0 &&
1965 event
.GetModifiers() == 0 )
1967 // Translate mousewheel actions into key up/down. This is
1968 // the simplest way of getting native behaviour: scrolling the
1969 // wheel moves selection up/down by one item.
1970 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1971 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1974 GetEventHandler()->ProcessEvent(kevent
);
1987 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1989 if ( IsPopupShown() )
1991 // pass it to the popped up control
1992 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1996 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1998 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
2000 if ( mainCtrl
->HandleAsNavigationKey(event
) )
2004 if ( IsKeyPopupToggle(event
) )
2010 int comboStyle
= GetWindowStyle();
2011 wxComboPopup
* popupInterface
= GetPopupControl();
2013 if ( !popupInterface
)
2019 int keycode
= event
.GetKeyCode();
2021 if ( (comboStyle
& wxCB_READONLY
) ||
2022 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
2024 popupInterface
->OnComboKeyEvent(event
);
2031 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
2033 if ( IsPopupShown() )
2035 // pass it to the popped up control
2036 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2040 wxComboPopup
* popupInterface
= GetPopupControl();
2041 if ( popupInterface
)
2043 popupInterface
->OnComboCharEvent(event
);
2052 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
2054 // On Mac, setting focus here leads to infinite recursion and eventually
2055 // a crash due to the SetFocus call producing another event.
2056 // Handle Mac in OnIdleEvent using m_resetFocus.
2058 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2060 if ( GetTextCtrl() && !GetTextCtrl()->HasFocus() )
2063 m_resetFocus
= true;
2065 GetTextCtrl()->SetFocus();
2073 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2077 m_resetFocus
= false;
2078 if ( GetTextCtrl() )
2079 GetTextCtrl()->SetFocus();
2083 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2086 // left margin may also have changed
2087 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2088 m_marginLeft
= GetNativeTextIndent();
2092 // ----------------------------------------------------------------------------
2094 // ----------------------------------------------------------------------------
2096 // Create popup window and the child control
2097 void wxComboCtrlBase::CreatePopup()
2099 wxComboPopup
* popupInterface
= m_popupInterface
;
2104 #ifdef wxComboPopupWindowBase2
2105 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2107 #if !USES_GENERICTLW
2108 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2110 int tlwFlags
= wxNO_BORDER
;
2111 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2112 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2115 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2116 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2117 wxPoint(-21,-21), wxSize(20, 20),
2120 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2121 wxPoint(-21,-21), wxSize(20, 20),
2125 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2128 #endif // wxComboPopupWindowBase2
2130 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2131 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2133 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2134 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2137 popupInterface
->Create(m_winPopup
);
2138 m_popup
= popup
= popupInterface
->GetControl();
2140 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2141 popup
->PushEventHandler( m_popupEvtHandler
);
2143 // This may be helpful on some platforms
2144 // (eg. it bypasses a wxGTK popupwindow bug where
2145 // window is not initially hidden when it should be)
2148 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2151 // Destroy popup window and the child control
2152 void wxComboCtrlBase::DestroyPopup()
2157 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2159 wxDELETE(m_popupEvtHandler
);
2161 if ( m_popupInterface
)
2163 // NB: DestroyPopup() performs 'delete this'.
2164 m_popupInterface
->DestroyPopup();
2165 m_popupInterface
= NULL
;
2170 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2171 wxDELETE(m_popupWinEvtHandler
);
2172 m_winPopup
->Destroy();
2179 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2181 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2185 iface
->InitBase(this);
2188 m_popupInterface
= iface
;
2190 if ( !iface
->LazyCreate() )
2199 // This must be done after creation
2200 if ( !m_valueString
.empty() )
2202 iface
->SetStringValue(m_valueString
);
2207 // Ensures there is atleast the default popup
2208 void wxComboCtrlBase::EnsurePopupControl()
2210 if ( !m_popupInterface
)
2211 SetPopupControl(NULL
);
2214 void wxComboCtrlBase::OnButtonClick()
2216 // Derived classes can override this method for totally custom
2218 switch ( GetPopupWindowState() )
2235 void wxComboCtrlBase::Popup()
2237 wxCommandEvent
event(wxEVT_COMBOBOX_DROPDOWN
, GetId());
2238 event
.SetEventObject(this);
2239 HandleWindowEvent(event
);
2244 void wxComboCtrlBase::ShowPopup()
2246 EnsurePopupControl();
2247 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2249 if ( IsPopupWindowState(Animating
) )
2254 // Space above and below
2260 wxSize ctrlSz
= GetSize();
2262 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2263 scrPos
= GetParent()->ClientToScreen(GetPosition());
2265 spaceAbove
= scrPos
.y
;
2266 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2268 maxHeightPopup
= spaceBelow
;
2269 if ( spaceAbove
> spaceBelow
)
2270 maxHeightPopup
= spaceAbove
;
2273 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2275 if ( widthPopup
< m_widthMinPopup
)
2276 widthPopup
= m_widthMinPopup
;
2278 wxWindow
* winPopup
= m_winPopup
;
2281 // Need to disable tab traversal of parent
2283 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2284 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2285 // that if transient popup is open, then tab traversal is to be ignored.
2286 // However, I think this code would still be needed for cases where
2287 // transient popup doesn't work yet (wxWinCE?).
2288 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2289 wxWindow
* parent
= mainCtrl
->GetParent();
2290 int parentFlags
= parent
->GetWindowStyle();
2291 if ( parentFlags
& wxTAB_TRAVERSAL
)
2293 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2294 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2300 winPopup
= m_winPopup
;
2310 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2312 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2313 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2316 popup
->SetSize(adjustedSize
);
2318 m_popupInterface
->OnPopup();
2321 // Reposition and resize popup window
2324 wxSize szp
= popup
->GetSize();
2327 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2329 // Default anchor is wxLEFT
2330 int anchorSide
= m_anchorSide
;
2332 anchorSide
= wxLEFT
;
2334 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2335 int leftX
= scrPos
.x
- m_extLeft
;
2337 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2340 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2342 // If there is not enough horizontal space, anchor on the other side.
2343 // If there is no space even then, place the popup at x 0.
2344 if ( anchorSide
== wxRIGHT
)
2348 if ( (leftX
+szp
.x
) < screenWidth
)
2349 anchorSide
= wxLEFT
;
2356 if ( (leftX
+szp
.x
) >= screenWidth
)
2359 anchorSide
= wxRIGHT
;
2365 // Select x coordinate according to the anchor side
2366 if ( anchorSide
== wxRIGHT
)
2368 else if ( anchorSide
== wxLEFT
)
2373 int showFlags
= CanDeferShow
;
2375 if ( spaceBelow
< szp
.y
)
2377 popupY
= scrPos
.y
- szp
.y
;
2378 showFlags
|= ShowAbove
;
2381 #if INSTALL_TOPLEV_HANDLER
2382 // Put top level window event handler into place
2383 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2385 if ( !m_toplevEvtHandler
)
2386 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2388 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2390 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2391 toplev
->PushEventHandler( m_toplevEvtHandler
);
2395 // Set string selection (must be this way instead of SetStringSelection)
2398 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2399 m_text
->SelectAll();
2401 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2405 // This is neede since focus/selection indication may change when popup is shown
2409 // This must be after SetStringValue
2410 m_popupWinState
= Animating
;
2412 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2415 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2416 AnimateShow( popupWinRect
, showFlags
) )
2418 DoShowPopup( popupWinRect
, showFlags
);
2422 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2427 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2429 wxWindow
* winPopup
= m_winPopup
;
2431 if ( IsPopupWindowState(Animating
) )
2433 // Make sure the popup window is shown in the right position.
2434 // Should not matter even if animation already did this.
2436 // Some platforms (GTK) may like SetSize and Move to be separate
2437 // (though the bug was probably fixed).
2438 winPopup
->SetSize( rect
);
2440 #if USES_WXPOPUPTRANSIENTWINDOW
2441 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2442 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2447 m_popupWinState
= Visible
;
2449 // If popup window was a generic top-level window, or the
2450 // wxPopupWindow implemenation on this platform is classified as
2451 // perfect, then we should be able to safely set focus to the popup
2453 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2454 m_popup
->SetFocus();
2456 else if ( IsPopupWindowState(Hidden
) )
2458 // Animation was aborted
2460 wxASSERT( !winPopup
->IsShown() );
2462 m_popupWinState
= Hidden
;
2468 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2470 // Just in case, avoid double dismiss
2471 if ( IsPopupWindowState(Hidden
) )
2474 // This must be set before focus - otherwise there will be recursive
2475 // OnPopupDismisses.
2476 m_popupWinState
= Hidden
;
2479 m_winPopup
->Disable();
2481 // Inform popup control itself
2482 m_popupInterface
->OnDismiss();
2484 if ( m_popupEvtHandler
)
2485 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2487 #if INSTALL_TOPLEV_HANDLER
2488 // Remove top level window event handler
2489 if ( m_toplevEvtHandler
)
2491 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2493 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2497 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2499 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2500 m_timeCanAcceptClick
+= 150;
2502 // If cursor not on dropdown button, then clear its state
2503 // (technically not required by all ports, but do it for all just in case)
2504 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2507 // Return parent's tab traversal flag.
2508 // See ShowPopup for notes.
2509 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2511 wxWindow
* parent
= GetParent();
2512 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2513 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2516 // refresh control (necessary even if m_text)
2521 if ( generateEvent
)
2523 wxCommandEvent
event(wxEVT_COMBOBOX_CLOSEUP
, GetId());
2524 event
.SetEventObject(this);
2525 HandleWindowEvent(event
);
2529 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2531 // Should be able to call this without popup interface
2532 if ( IsPopupWindowState(Hidden
) )
2535 // transfer value and show it in textctrl, if any
2536 if ( !IsPopupWindowState(Animating
) )
2537 SetValueByUser( m_popupInterface
->GetStringValue() );
2541 OnPopupDismiss(generateEvent
);
2544 // ----------------------------------------------------------------------------
2545 // customization methods
2546 // ----------------------------------------------------------------------------
2548 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2549 int side
, int spacingX
)
2554 m_btnSpacingX
= spacingX
;
2556 if ( width
> 0 || height
> 0 || spacingX
)
2557 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2562 wxSize
wxComboCtrlBase::GetButtonSize()
2564 if ( m_btnSize
.x
> 0 )
2567 wxSize
retSize(m_btnWid
,m_btnHei
);
2569 // Need to call CalculateAreas now if button size is
2570 // is not explicitly specified.
2571 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2575 retSize
= m_btnSize
;
2581 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2583 const wxBitmap
& bmpPressed
,
2584 const wxBitmap
& bmpHover
,
2585 const wxBitmap
& bmpDisabled
)
2587 m_bmpNormal
= bmpNormal
;
2588 m_blankButtonBg
= blankButtonBg
;
2590 if ( bmpPressed
.IsOk() )
2591 m_bmpPressed
= bmpPressed
;
2593 m_bmpPressed
= bmpNormal
;
2595 if ( bmpHover
.IsOk() )
2596 m_bmpHover
= bmpHover
;
2598 m_bmpHover
= bmpNormal
;
2600 if ( bmpDisabled
.IsOk() )
2601 m_bmpDisabled
= bmpDisabled
;
2603 m_bmpDisabled
= bmpNormal
;
2608 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2612 // move textctrl accordingly
2613 wxRect r
= m_text
->GetRect();
2614 int inc
= width
- m_widthCustomPaint
;
2617 m_text
->SetSize( r
);
2620 m_widthCustomPaint
= width
;
2625 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2627 // For general sanity's sake, we ignore top margin. Instead
2628 // we will always try to center the text vertically.
2631 if ( margins
.x
!= -1 )
2633 m_marginLeft
= margins
.x
;
2634 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2638 m_marginLeft
= GetNativeTextIndent();
2639 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2642 if ( margins
.y
!= -1 )
2652 wxPoint
wxComboCtrlBase::DoGetMargins() const
2654 return wxPoint(m_marginLeft
, -1);
2657 #if WXWIN_COMPATIBILITY_2_8
2658 void wxComboCtrlBase::SetTextIndent( int indent
)
2662 m_marginLeft
= GetNativeTextIndent();
2663 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2667 m_marginLeft
= indent
;
2668 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2674 wxCoord
wxComboCtrlBase::GetTextIndent() const
2676 return m_marginLeft
;
2680 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2682 return DEFAULT_TEXT_INDENT
;
2685 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2687 m_textCtrlStyle
= style
;
2690 m_text
->SetWindowStyle(style
);
2693 // ----------------------------------------------------------------------------
2694 // wxTextEntry interface
2695 // ----------------------------------------------------------------------------
2697 wxString
wxComboCtrlBase::DoGetValue() const
2700 return m_text
->GetValue();
2701 return m_valueString
;
2704 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2707 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2710 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2712 // Note: before wxComboCtrl inherited from wxTextEntry,
2713 // this code used to be in SetValueWithEvent().
2715 // Since wxComboPopup may want to paint the combo as well, we need
2716 // to set the string value here (as well as sometimes in ShowPopup).
2717 if ( m_valueString
!= value
)
2720 wxString trueValue
= value
;
2722 // Conform to wxComboBox behaviour: read-only control can only accept
2723 // valid list items and empty string
2724 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2726 found
= m_popupInterface
->FindItem(value
,
2732 m_valueString
= trueValue
;
2734 EnsurePopupControl();
2736 if ( m_popupInterface
)
2737 m_popupInterface
->SetStringValue(trueValue
);
2744 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2746 // NB: Order of function calls is important here. Otherwise
2747 // the SelectAll() may not work.
2751 m_text
->SetValue(value
);
2753 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2754 m_text
->SelectAll();
2760 // In this SetValue variant wxComboPopup::SetStringValue is not called
2761 void wxComboCtrlBase::SetText(const wxString
& value
)
2763 // Unlike in SetValue(), this must be called here or
2764 // the behaviour will no be consistent in readonlys.
2765 EnsurePopupControl();
2767 m_valueString
= value
;
2772 m_text
->SetValue( value
);
2778 void wxComboCtrlBase::Copy()
2784 void wxComboCtrlBase::Cut()
2790 void wxComboCtrlBase::Paste()
2796 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2799 m_text
->SetInsertionPoint(pos
);
2802 long wxComboCtrlBase::GetInsertionPoint() const
2805 return m_text
->GetInsertionPoint();
2810 long wxComboCtrlBase::GetLastPosition() const
2813 return m_text
->GetLastPosition();
2818 void wxComboCtrlBase::WriteText(const wxString
& text
)
2822 m_text
->WriteText(text
);
2823 OnSetValue(m_text
->GetValue());
2831 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2835 if ( flags
& SetValue_SendEvent
)
2836 m_text
->SetValue(value
);
2838 m_text
->ChangeValue(value
);
2844 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2848 m_text
->Replace(from
, to
, value
);
2849 OnSetValue(m_text
->GetValue());
2853 void wxComboCtrlBase::Remove(long from
, long to
)
2857 m_text
->Remove(from
, to
);
2858 OnSetValue(m_text
->GetValue());
2862 void wxComboCtrlBase::SetSelection(long from
, long to
)
2865 m_text
->SetSelection(from
, to
);
2868 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2872 m_text
->GetSelection(from
, to
);
2881 bool wxComboCtrlBase::IsEditable() const
2884 return m_text
->IsEditable();
2888 void wxComboCtrlBase::SetEditable(bool editable
)
2891 m_text
->SetEditable(editable
);
2894 void wxComboCtrlBase::Undo()
2900 void wxComboCtrlBase::Redo()
2906 bool wxComboCtrlBase::CanUndo() const
2909 return m_text
->CanUndo();
2914 bool wxComboCtrlBase::CanRedo() const
2917 return m_text
->CanRedo();
2922 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2927 res
= m_text
->SetHint(hint
);
2932 wxString
wxComboCtrlBase::GetHint() const
2937 #endif // wxUSE_COMBOCTRL