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/msw/private.h"
32 #include "wx/combobox.h"
33 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr
[] = "comboBox";
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 wxDEFINE_FLAGS( wxComboBoxStyle
)
40 wxBEGIN_FLAGS( wxComboBoxStyle
)
41 // new style border flags, we put them first to
42 // use them for streaming out
43 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
44 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
45 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
46 wxFLAGS_MEMBER(wxBORDER_RAISED
)
47 wxFLAGS_MEMBER(wxBORDER_STATIC
)
48 wxFLAGS_MEMBER(wxBORDER_NONE
)
50 // old style border flags
51 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
52 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
53 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
54 wxFLAGS_MEMBER(wxRAISED_BORDER
)
55 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
56 wxFLAGS_MEMBER(wxBORDER
)
58 // standard window styles
59 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
60 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
61 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
62 wxFLAGS_MEMBER(wxWANTS_CHARS
)
63 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
64 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
65 wxFLAGS_MEMBER(wxVSCROLL
)
66 wxFLAGS_MEMBER(wxHSCROLL
)
68 wxFLAGS_MEMBER(wxCB_SIMPLE
)
69 wxFLAGS_MEMBER(wxCB_SORT
)
70 wxFLAGS_MEMBER(wxCB_READONLY
)
71 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
73 wxEND_FLAGS( wxComboBoxStyle
)
75 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
77 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
78 wxEVENT_PROPERTY( Select
, wxEVT_COMBOBOX
, wxCommandEvent
)
79 wxEVENT_PROPERTY( TextEnter
, wxEVT_TEXT_ENTER
, wxCommandEvent
)
82 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
83 0 /*flags*/, wxT("Helpstring"), wxT("group"))
84 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
85 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
86 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
87 0 /*flags*/, wxT("Helpstring"), wxT("group"))
88 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
89 0 /*flags*/, wxT("Helpstring"), wxT("group"))
91 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
92 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
93 wxT("Helpstring"), wxT("group")) // style
94 wxEND_PROPERTIES_TABLE()
96 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
98 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
99 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
101 #endif // wxUSE_COMBOBOX
108 #include "wx/dcclient.h"
109 #include "wx/settings.h"
110 #include "wx/timer.h"
111 #include "wx/textctrl.h"
114 #include "wx/tooltip.h"
117 // ----------------------------------------------------------------------------
119 #define DEFAULT_DROPBUTTON_WIDTH 19
121 #define BMP_BUTTON_MARGIN 4
123 #define DEFAULT_POPUP_HEIGHT 400
125 #define DEFAULT_TEXT_INDENT 3
127 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
130 #if defined(__WXMSW__)
132 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
133 #include "wx/frame.h"
134 #define wxCC_GENERIC_TLW_IS_FRAME
135 #define wxComboCtrlGenericTLW wxFrame
137 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
138 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
139 // native controls work on it like normal.
140 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
141 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
142 #define FOCUS_RING 0 // No focus ring on wxMSW
144 //#undef wxUSE_POPUPWIN
145 //#define wxUSE_POPUPWIN 0
147 #elif defined(__WXGTK__)
149 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
150 // this bug: If wxDialog is hidden, its position becomes corrupt
151 // between hide and next show, but without internal coordinates being
152 // reflected (or something like that - atleast commenting out ->Hide()
153 // seemed to eliminate the position change).
155 #include "wx/dialog.h"
156 #define wxCC_GENERIC_TLW_IS_DIALOG
157 #define wxComboCtrlGenericTLW wxDialog
159 #if defined(__WXGTK20__)
160 # include "wx/gtk/private.h"
162 # include "wx/gtk1/private.h"
165 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
166 // 'perfect' popup, as it can successfully host child controls even in
167 // popups that are shown in modal dialogs.
169 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
170 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
171 // native controls work on it like normal.
172 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
173 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
174 #define FOCUS_RING 0 // No focus ring on wxGTK
176 #elif defined(__WXMAC__)
178 #include "wx/nonownedwnd.h"
179 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
180 #define wxComboCtrlGenericTLW wxNonOwnedWindow
182 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
183 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
184 // native controls work on it like normal.
185 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
186 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
187 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
189 #undef DEFAULT_DROPBUTTON_WIDTH
190 #define DEFAULT_DROPBUTTON_WIDTH 22
192 #define COMBO_MARGIN FOCUS_RING
196 #include "wx/dialog.h"
197 #define wxCC_GENERIC_TLW_IS_DIALOG
198 #define wxComboCtrlGenericTLW wxDialog
200 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
201 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
202 // native controls work on it like normal.
203 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
204 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
210 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
211 // what the wxUSE_POPUPWIN says.
212 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
213 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
214 #undef wxUSE_POPUPWIN
215 #define wxUSE_POPUPWIN 0
220 #include "wx/popupwin.h"
222 #undef USE_TRANSIENT_POPUP
223 #define USE_TRANSIENT_POPUP 0
227 // Define different types of popup windows
231 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
232 POPUPWIN_WXPOPUPWINDOW
= 2,
233 POPUPWIN_GENERICTLW
= 3
237 #if USE_TRANSIENT_POPUP
238 // wxPopupTransientWindow is implemented
240 #define wxComboPopupWindowBase wxPopupTransientWindow
241 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
242 #define USES_WXPOPUPTRANSIENTWINDOW 1
244 #if TRANSIENT_POPUPWIN_IS_PERFECT
246 #elif POPUPWIN_IS_PERFECT
247 #define wxComboPopupWindowBase2 wxPopupWindow
248 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
249 #define USES_WXPOPUPWINDOW 1
251 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
252 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
253 #define USES_GENERICTLW 1
257 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
259 #define wxComboPopupWindowBase wxPopupWindow
260 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
261 #define USES_WXPOPUPWINDOW 1
263 #if !POPUPWIN_IS_PERFECT
264 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
265 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
266 #define USES_GENERICTLW 1
270 // wxPopupWindow is not implemented
272 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
273 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
274 #define USES_GENERICTLW 1
279 #ifndef USES_WXPOPUPTRANSIENTWINDOW
280 #define USES_WXPOPUPTRANSIENTWINDOW 0
283 #ifndef USES_WXPOPUPWINDOW
284 #define USES_WXPOPUPWINDOW 0
287 #ifndef USES_GENERICTLW
288 #define USES_GENERICTLW 0
292 #if USES_WXPOPUPWINDOW
293 #define INSTALL_TOPLEV_HANDLER 1
295 #define INSTALL_TOPLEV_HANDLER 0
299 // Returns true if given popup window type can be classified as perfect
301 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
303 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
304 wxUnusedVar(popupWinType
);
307 return ( popupWinType
== POPUPWIN_GENERICTLW
308 #if POPUPWIN_IS_PERFECT
309 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
311 #if TRANSIENT_POPUPWIN_IS_PERFECT
312 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
321 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
325 // ----------------------------------------------------------------------------
326 // wxComboFrameEventHandler takes care of hiding the popup when events happen
327 // in its top level parent.
328 // ----------------------------------------------------------------------------
330 #if INSTALL_TOPLEV_HANDLER
333 // This will no longer be necessary after wxTransientPopupWindow
334 // works well on all platforms.
337 class wxComboFrameEventHandler
: public wxEvtHandler
340 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
341 virtual ~wxComboFrameEventHandler();
345 void OnIdle( wxIdleEvent
& event
);
346 void OnMouseEvent( wxMouseEvent
& event
);
347 void OnActivate( wxActivateEvent
& event
);
348 void OnResize( wxSizeEvent
& event
);
349 void OnMove( wxMoveEvent
& event
);
350 void OnMenuEvent( wxMenuEvent
& event
);
351 void OnClose( wxCloseEvent
& event
);
354 wxWindow
* m_focusStart
;
355 wxComboCtrlBase
* m_combo
;
358 DECLARE_EVENT_TABLE()
361 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
362 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
363 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
364 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
365 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
366 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
367 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
368 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
369 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
370 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
373 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
379 wxComboFrameEventHandler::~wxComboFrameEventHandler()
383 void wxComboFrameEventHandler::OnPopup()
385 m_focusStart
= ::wxWindow::FindFocus();
388 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
390 wxWindow
* winFocused
= ::wxWindow::FindFocus();
392 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
393 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
395 if ( !winFocused
|| (
396 winFocused
!= m_focusStart
&&
397 winFocused
!= popup
&&
398 winFocused
->GetParent() != popup
&&
399 winFocused
!= winpopup
&&
400 winFocused
->GetParent() != winpopup
&&
401 winFocused
!= m_combo
&&
402 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
406 m_combo
->HidePopup(true);
412 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
414 m_combo
->HidePopup(true);
418 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
420 m_combo
->HidePopup(true);
424 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
426 m_combo
->HidePopup(true);
430 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
432 m_combo
->HidePopup(true);
436 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
438 m_combo
->HidePopup(true);
442 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
444 m_combo
->HidePopup(true);
448 #endif // INSTALL_TOPLEV_HANDLER
450 // ----------------------------------------------------------------------------
451 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
453 // ----------------------------------------------------------------------------
455 class wxComboPopupWindow
: public wxComboPopupWindowBase
459 wxComboPopupWindow( wxComboCtrlBase
*parent
,
461 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
462 : wxComboPopupWindowBase(parent
,style
)
464 : wxComboPopupWindowBase(parent
,
475 #if USES_WXPOPUPTRANSIENTWINDOW
476 virtual bool Show( bool show
);
477 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
479 virtual void OnDismiss();
487 #if USES_WXPOPUPTRANSIENTWINDOW
488 bool wxComboPopupWindow::Show( bool show
)
490 // Guard against recursion
492 return wxComboPopupWindowBase::Show(show
);
496 wxPopupTransientWindow
* const
497 ptw
= static_cast<wxPopupTransientWindow
*>(this);
499 if ( show
!= ptw
->IsShown() )
502 // We used to do wxPopupTransientWindow::Popup here,
503 // but this would hide normal Show, which we are
504 // also going to need.
515 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
517 return wxPopupTransientWindow::ProcessLeftDown(event
);
520 // First thing that happens when a transient popup closes is that this method gets called.
521 void wxComboPopupWindow::OnDismiss()
523 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
524 wxASSERT_MSG( wxDynamicCast(combo
, wxComboCtrlBase
),
525 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
527 combo
->OnPopupDismiss(true);
529 #endif // USES_WXPOPUPTRANSIENTWINDOW
532 // ----------------------------------------------------------------------------
533 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
534 // of a popup window. It is separate so we can have different types
536 // ----------------------------------------------------------------------------
538 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
542 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
547 void OnSizeEvent( wxSizeEvent
& event
);
548 void OnKeyEvent(wxKeyEvent
& event
);
550 void OnActivate( wxActivateEvent
& event
);
554 wxComboCtrlBase
* m_combo
;
556 DECLARE_EVENT_TABLE()
560 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
561 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
562 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
563 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
565 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
567 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
571 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
573 // Block the event so that the popup control does not get auto-resized.
576 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
578 // Relay keyboard event to the main child controls
579 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
580 wxWindowList::iterator node
= children
.begin();
581 wxWindow
* child
= (wxWindow
*)*node
;
582 child
->GetEventHandler()->ProcessEvent(event
);
586 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
588 if ( !event
.GetActive() )
590 // Tell combo control that we are dismissed.
591 m_combo
->HidePopup(true);
599 // ----------------------------------------------------------------------------
602 // ----------------------------------------------------------------------------
604 wxComboPopup::~wxComboPopup()
608 void wxComboPopup::OnPopup()
612 void wxComboPopup::OnDismiss()
616 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
618 return wxStaticCast(m_combo
, wxComboCtrl
);
621 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
623 int WXUNUSED(maxHeight
) )
625 return wxSize(minWidth
,prefHeight
);
628 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
629 wxDC
& dc
, const wxRect
& rect
)
631 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
633 combo
->PrepareBackground(dc
,rect
,0);
635 dc
.DrawText( combo
->GetValue(),
636 rect
.x
+ combo
->m_marginLeft
,
637 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
641 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
643 DefaultPaintComboControl(m_combo
,dc
,rect
);
646 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
651 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
656 void wxComboPopup::OnComboDoubleClick()
660 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
664 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
665 wxString
* WXUNUSED(trueItem
))
670 bool wxComboPopup::LazyCreate()
675 void wxComboPopup::Dismiss()
677 m_combo
->HidePopup(true);
680 void wxComboPopup::DestroyPopup()
682 // Here we make sure that the popup control's Destroy() gets called.
683 // This is necessary for the wxPersistentWindow to work properly.
684 wxWindow
* popupCtrl
= GetControl();
687 // While all wxComboCtrl examples have m_popupInterface and
688 // popupCtrl as the same class (that will be deleted via the
689 // Destroy() call below), it is technically still possible to
690 // have implementations where they are in fact not same
691 // multiple-inherited class. Here we use C++ RTTI to check for
694 // It is probably better to delete m_popupInterface first, so
695 // that it retains access to its popup control window.
696 if ( dynamic_cast<void*>(this) !=
697 dynamic_cast<void*>(popupCtrl
) )
700 popupCtrl
->Destroy();
708 // ----------------------------------------------------------------------------
710 // ----------------------------------------------------------------------------
713 // This is pushed to the event handler queue of the child textctrl.
715 class wxComboBoxExtraInputHandler
: public wxEvtHandler
719 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
724 virtual ~wxComboBoxExtraInputHandler() { }
725 void OnKey(wxKeyEvent
& event
);
726 void OnFocus(wxFocusEvent
& event
);
729 wxComboCtrlBase
* m_combo
;
732 DECLARE_EVENT_TABLE()
736 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
737 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
738 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
739 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
740 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
741 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
745 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
747 // Let the wxComboCtrl event handler have a go first.
748 wxComboCtrlBase
* combo
= m_combo
;
750 wxKeyEvent
redirectedEvent(event
);
751 redirectedEvent
.SetId(combo
->GetId());
752 redirectedEvent
.SetEventObject(combo
);
754 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
756 // Don't let TAB through to the text ctrl - looks ugly
757 if ( event
.GetKeyCode() != WXK_TAB
)
762 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
764 // FIXME: This code does run when control is clicked,
765 // yet on Windows it doesn't select all the text.
766 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
767 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
769 if ( m_combo
->GetTextCtrl() )
770 m_combo
->GetTextCtrl()->SelectAll();
772 m_combo
->SelectAll();
775 // Send focus indication to parent.
776 // NB: This is needed for cases where the textctrl gets focus
777 // instead of its parent. While this may trigger multiple
778 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
779 // from combo's focus event handler), they should be quite
781 wxFocusEvent
evt2(event
);
782 evt2
.SetId(m_combo
->GetId());
783 evt2
.SetEventObject(m_combo
);
784 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
791 // This is pushed to the event handler queue of the control in popup.
794 class wxComboPopupEvtHandler
: public wxEvtHandler
798 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
802 m_beenInside
= false;
804 // Let's make it so that the popup control will not receive mouse
805 // events until mouse left button has been up.
806 m_blockEventsToPopup
= true;
808 virtual ~wxComboPopupEvtHandler() { }
810 void OnMouseEvent( wxMouseEvent
& event
);
812 // Called from wxComboCtrlBase::OnPopupDismiss
813 void OnPopupDismiss()
815 m_beenInside
= false;
816 m_blockEventsToPopup
= true;
820 wxComboCtrlBase
* m_combo
;
823 bool m_blockEventsToPopup
;
826 DECLARE_EVENT_TABLE()
830 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
831 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
835 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
837 wxPoint pt
= event
.GetPosition();
838 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
839 int evtType
= event
.GetEventType();
840 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
841 bool relayToButton
= false;
845 if ( !isInside
|| !m_combo
->IsPopupShown() )
847 // Mouse is outside the popup or popup is not actually shown (yet)
849 if ( evtType
== wxEVT_MOTION
||
850 evtType
== wxEVT_LEFT_DOWN
||
851 evtType
== wxEVT_LEFT_UP
||
852 evtType
== wxEVT_RIGHT_DOWN
)
854 // Block motion and click events outside the popup
860 // Mouse is inside the popup, which is fully shown
864 // Do not let the popup control respond to mouse events until
865 // mouse press used to display the popup has been lifted. This
866 // is important for users with slower mouse fingers or mouse
867 // drivers. Note that we have some redundancy here, just in
868 // case the popup is some native control that does not emit all
869 // mouse event types.
870 if ( evtType
== wxEVT_MOTION
)
872 if ( m_blockEventsToPopup
)
874 if ( event
.LeftIsDown() )
877 m_blockEventsToPopup
= false;
880 else if ( evtType
== wxEVT_LEFT_DOWN
)
882 if ( m_blockEventsToPopup
)
883 m_blockEventsToPopup
= false;
885 else if ( evtType
== wxEVT_LEFT_UP
)
887 if ( m_blockEventsToPopup
)
889 // On first left up, stop blocking mouse events (but still
891 m_blockEventsToPopup
= false;
894 // Also, this button press was (probably) used to display
895 // the popup, so relay it back to the drop-down button
896 // (which supposedly originated it). This is necessary to
897 // refresh it properly.
898 relayToButton
= true;
901 else if ( m_blockEventsToPopup
)
908 // Some mouse events to popup that happen outside it, before cursor
909 // has been inside the popup, need to be ignored by it but relayed to
912 if ( evtType
== wxEVT_LEFT_UP
)
914 if ( !m_combo
->IsPopupShown() )
917 relayToButton
= true;
919 else if ( !isInside
&& !m_beenInside
)
921 // Popup is shown but the cursor is not inside, nor it has been
922 relayToButton
= true;
928 wxWindow
* btn
= m_combo
->GetButton();
930 btn
->GetEventHandler()->ProcessEvent(event
);
932 // Bypass the event handling mechanism. Using it would be
933 // confusing for the platform-specific wxComboCtrl
935 m_combo
->HandleButtonMouseEvent(event
, 0);
939 // ----------------------------------------------------------------------------
940 // wxComboCtrlTextCtrl
941 // ----------------------------------------------------------------------------
943 class wxComboCtrlTextCtrl
: public wxTextCtrl
946 wxComboCtrlTextCtrl() : wxTextCtrl() { }
947 virtual ~wxComboCtrlTextCtrl() { }
949 virtual wxWindow
*GetMainWindowOfCompositeControl()
951 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
953 // Returning this instead of just 'parent' lets FindFocus work
954 // correctly even when parent control is a child of a composite
955 // generic control (as is case with wxGenericDatePickerCtrl).
956 return combo
->GetMainWindowOfCompositeControl();
960 // ----------------------------------------------------------------------------
962 // ----------------------------------------------------------------------------
965 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
966 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
967 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
968 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
969 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
970 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
971 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
972 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
973 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
977 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
979 void wxComboCtrlBase::Init()
983 m_popupWinState
= Hidden
;
986 m_popupInterface
= NULL
;
988 m_popupEvtHandler
= NULL
;
989 m_textEvtHandler
= NULL
;
991 #if INSTALL_TOPLEV_HANDLER
992 m_toplevEvtHandler
= NULL
;
995 m_mainCtrlWnd
= this;
998 m_widthMinPopup
= -1;
1000 m_widthCustomPaint
= 0;
1001 m_widthCustomBorder
= 0;
1004 m_btnWidDefault
= 0;
1005 m_blankButtonBg
= false;
1006 m_ignoreEvtText
= 0;
1007 m_popupWinType
= POPUPWIN_NONE
;
1008 m_btnWid
= m_btnHei
= -1;
1009 m_btnSide
= wxRIGHT
;
1016 m_textCtrlStyle
= 0;
1017 m_timeCanAcceptClick
= 0;
1019 m_resetFocus
= false;
1020 m_hasTcBgCol
= false;
1023 bool wxComboCtrlBase::Create(wxWindow
*parent
,
1025 const wxString
& value
,
1029 const wxValidator
& validator
,
1030 const wxString
& name
)
1032 if ( !wxControl::Create(parent
,
1036 style
| wxWANTS_CHARS
,
1041 m_valueString
= value
;
1045 m_marginLeft
= GetNativeTextIndent();
1047 m_iFlags
|= wxCC_IFLAG_CREATED
;
1049 // If x and y indicate valid size, wxSizeEvent won't be
1050 // emitted automatically, so we need to add artificial one.
1051 if ( size
.x
> 0 && size
.y
> 0 )
1053 wxSizeEvent
evt(size
,GetId());
1054 evt
.SetEventObject(this);
1055 GetEventHandler()->AddPendingEvent(evt
);
1061 void wxComboCtrlBase::InstallInputHandlers()
1065 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1066 m_text
->PushEventHandler(m_textEvtHandler
);
1071 wxComboCtrlBase::CreateTextCtrl(int style
)
1073 if ( !(m_windowStyle
& wxCB_READONLY
) )
1078 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1079 // not used by the wxPropertyGrid and therefore the tab is processed by
1080 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1081 // navigation event is then sent to the wrong window.
1082 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1084 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1085 style
|= wxTE_PROCESS_ENTER
;
1087 // Ignore EVT_TEXT generated by the constructor (but only
1088 // if the event redirector already exists)
1089 // NB: This must be " = 1" instead of "++";
1090 if ( m_textEvtHandler
)
1091 m_ignoreEvtText
= 1;
1093 m_ignoreEvtText
= 0;
1095 m_text
= new wxComboCtrlTextCtrl();
1096 m_text
->Create(this, wxID_ANY
, m_valueString
,
1097 wxDefaultPosition
, wxSize(10,-1),
1100 // Connecting the events is currently the most reliable way
1101 wxWindowID id
= m_text
->GetId();
1102 m_text
->Connect(id
, wxEVT_TEXT
,
1103 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1105 m_text
->Connect(id
, wxEVT_TEXT_ENTER
,
1106 wxCommandEventHandler(wxComboCtrlBase::OnTextCtrlEvent
),
1109 m_text
->SetHint(m_hintText
);
1113 void wxComboCtrlBase::OnThemeChange()
1115 // Because wxComboCtrl has transparent parts on most platforms, we
1116 // don't want to touch the actual background colour. Instead, we just
1117 // usually re-obtain m_tcBgCol here.
1119 #if defined(__WXMSW__) || defined(__WXGTK__)
1120 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1122 wxVisualAttributes vattrs
;
1123 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1124 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1127 if ( !m_hasTcBgCol
)
1128 m_tcBgCol
= vattrs
.colBg
;
1131 // Only change the colours if application has not specified
1135 SetOwnForegroundColour(vattrs
.colFg
);
1137 if ( !HasTransparentBackground() )
1139 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1141 #endif // !__WXMAC__
1144 wxComboCtrlBase::~wxComboCtrlBase()
1149 #if INSTALL_TOPLEV_HANDLER
1150 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1151 m_toplevEvtHandler
= NULL
;
1157 m_text
->RemoveEventHandler(m_textEvtHandler
);
1159 delete m_textEvtHandler
;
1163 // ----------------------------------------------------------------------------
1165 // ----------------------------------------------------------------------------
1167 // Recalculates button and textctrl areas
1168 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1170 wxSize sz
= GetClientSize();
1171 int customBorder
= m_widthCustomBorder
;
1172 int btnBorder
; // border for button only
1174 // check if button should really be outside the border: we'll do it it if
1175 // its platform default or bitmap+pushbutton background is used, but not if
1176 // there is vertical size adjustment or horizontal spacing.
1177 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1178 (m_bmpNormal
.IsOk() && m_blankButtonBg
) ) &&
1179 m_btnSpacingX
== 0 &&
1182 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1185 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1186 m_btnSpacingX
== 0 && !m_bmpNormal
.IsOk() )
1188 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1193 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1194 btnBorder
= customBorder
;
1197 // Defaul indentation
1198 if ( m_marginLeft
< 0 )
1199 m_marginLeft
= GetNativeTextIndent();
1201 int butWidth
= btnWidth
;
1203 if ( butWidth
<= 0 )
1204 butWidth
= m_btnWidDefault
;
1206 m_btnWidDefault
= butWidth
;
1208 if ( butWidth
<= 0 )
1211 int butHeight
= sz
.y
- btnBorder
*2;
1213 // Adjust button width
1215 butWidth
= m_btnWid
;
1218 // Adjust button width to match aspect ratio
1219 // (but only if control is smaller than best size).
1220 int bestHeight
= GetBestSize().y
;
1221 int height
= GetSize().y
;
1223 if ( height
< bestHeight
)
1225 // Make very small buttons square, as it makes
1226 // them accommodate arrow image better and still
1229 butWidth
= (height
*butWidth
)/bestHeight
;
1231 butWidth
= butHeight
;
1235 // Adjust button height
1237 butHeight
= m_btnHei
;
1239 // Use size of normal bitmap if...
1242 // button width is set to default and blank button bg is not drawn
1243 if ( m_bmpNormal
.IsOk() )
1245 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1246 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1248 // If drawing blank button background, we need to add some margin.
1249 if ( m_blankButtonBg
)
1251 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1252 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1255 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1256 butWidth
= bmpReqWidth
;
1257 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1258 butHeight
= bmpReqHeight
;
1260 // Need to fix height?
1261 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1263 int newY
= butHeight
+(customBorder
*2);
1264 SetClientSize(wxDefaultCoord
,newY
);
1265 if ( m_bmpNormal
.IsOk() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1266 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1268 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1274 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1276 m_btnSize
.x
= butWidth
;
1277 m_btnSize
.y
= butHeight
;
1279 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1280 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1281 m_btnArea
.width
= butAreaWid
;
1282 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1284 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1285 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1286 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1287 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1292 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1293 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1298 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1303 wxSize sz
= GetClientSize();
1305 int customBorder
= m_widthCustomBorder
;
1306 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1310 if ( !m_widthCustomPaint
)
1312 // No special custom paint area - we can use 0 left margin
1314 if ( m_text
->SetMargins(0) )
1315 textCtrlXAdjust
= 0;
1316 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1320 // There is special custom paint area - it is better to
1321 // use some margin with the wxTextCtrl.
1322 m_text
->SetMargins(m_marginLeft
);
1323 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1324 m_marginLeft
+ textCtrlXAdjust
;
1327 // Centre textctrl vertically, if needed
1328 #if !TEXTCTRL_TEXT_CENTERED
1329 int tcSizeY
= m_text
->GetBestSize().y
;
1330 int diff0
= sz
.y
- tcSizeY
;
1331 int y
= textCtrlYAdjust
+ (diff0
/2);
1333 wxUnusedVar(textCtrlYAdjust
);
1337 if ( y
< customBorder
)
1342 m_tcArea
.width
- m_tcArea
.x
- x
,
1345 // Make sure textctrl doesn't exceed the bottom custom border
1346 wxSize tsz
= m_text
->GetSize();
1347 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1350 tsz
.y
= tsz
.y
- diff1
- 1;
1351 m_text
->SetSize(tsz
);
1356 // If it has border, have textctrl fill the entire text field.
1357 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1359 m_tcArea
.width
- m_widthCustomPaint
,
1364 wxSize
wxComboCtrlBase::DoGetBestSize() const
1366 int width
= m_text
? m_text
->GetBestSize().x
: 80;
1368 return GetSizeFromTextSize(width
);
1371 wxSize
wxComboCtrlBase::DoGetSizeFromTextSize(int xlen
, int ylen
) const
1373 // Calculate close-to-native control height
1377 #if defined(__WXMSW__) && !defined(__WXUNIVERSAL__)
1378 fhei
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(GetCharHeight());
1379 #elif defined(__WXGTK__) && !defined(__WXUNIVERSAL__)
1380 // Control creation is not entirely cheap, so cache the heights to
1381 // avoid repeatedly creating dummy controls:
1382 static wxString s_last_font
;
1383 static int s_last_fhei
= -1;
1385 if ( m_font
.IsOk() )
1386 fontdesc
= m_font
.GetNativeFontInfoDesc();
1387 if ( s_last_fhei
!= -1 && fontdesc
== s_last_font
)
1393 wxComboBox
* cb
= new wxComboBox
;
1395 cb
->Create(const_cast<wxComboCtrlBase
*>(this), wxID_ANY
);
1396 if ( m_font
.IsOk() )
1397 cb
->SetFont(m_font
);
1398 s_last_font
= fontdesc
;
1399 s_last_fhei
= fhei
= cb
->GetBestSize().y
;
1403 if ( m_font
.IsOk() )
1404 fhei
= (m_font
.GetPointSize()*2) + 5;
1405 else if ( wxNORMAL_FONT
->IsOk() )
1406 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1409 #endif // only for wxComboBox on MSW or GTK
1411 // Need to force height to accommodate bitmap?
1412 int btnSizeY
= m_btnSize
.y
;
1413 if ( m_bmpNormal
.IsOk() && fhei
< btnSizeY
)
1416 // Control height doesn't depend on border
1419 int border = m_windowStyle & wxBORDER_MASK;
1420 if ( border == wxSIMPLE_BORDER )
1422 else if ( border == wxNO_BORDER )
1423 fhei += (m_widthCustomBorder*2);
1430 // these are the numbers from the HIG:
1431 switch ( m_windowVariant
)
1433 case wxWINDOW_VARIANT_NORMAL
:
1437 case wxWINDOW_VARIANT_SMALL
:
1440 case wxWINDOW_VARIANT_MINI
:
1446 fhei
+= 2 * FOCUS_RING
;
1449 int fwid
= xlen
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1451 // Add the margins we have previously set
1452 wxPoint
marg( GetMargins() );
1453 fwid
+= wxMax(0, marg
.x
);
1454 fhei
+= wxMax(0, marg
.y
);
1457 fhei
+= ylen
- GetCharHeight();
1459 return wxSize(fwid
, fhei
);
1462 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1467 // defined by actual wxComboCtrls
1473 // ----------------------------------------------------------------------------
1474 // standard operations
1475 // ----------------------------------------------------------------------------
1477 bool wxComboCtrlBase::Enable(bool enable
)
1479 if ( !wxControl::Enable(enable
) )
1483 m_btn
->Enable(enable
);
1485 m_text
->Enable(enable
);
1492 bool wxComboCtrlBase::Show(bool show
)
1494 if ( !wxControl::Show(show
) )
1506 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1508 if ( !wxControl::SetFont(font
) )
1513 // Without hiding the wxTextCtrl there would be some
1514 // visible 'flicker' (at least on Windows XP).
1516 m_text
->SetFont(font
);
1525 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1527 wxControl::DoSetToolTip(tooltip
);
1529 // Set tool tip for button and text box
1532 const wxString
&tip
= tooltip
->GetTip();
1533 if ( m_text
) m_text
->SetToolTip(tip
);
1534 if ( m_btn
) m_btn
->SetToolTip(tip
);
1538 if ( m_text
) m_text
->SetToolTip( NULL
);
1539 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1542 #endif // wxUSE_TOOLTIPS
1544 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1546 if ( wxControl::SetForegroundColour(colour
) )
1549 m_text
->SetForegroundColour(colour
);
1555 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1558 m_text
->SetBackgroundColour(colour
);
1560 m_hasTcBgCol
= true;
1564 wxColour
wxComboCtrlBase::GetBackgroundColour() const
1567 return m_text
->GetBackgroundColour();
1571 // ----------------------------------------------------------------------------
1573 // ----------------------------------------------------------------------------
1575 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1576 // prepare combo box background on area in a way typical on platform
1577 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1579 wxSize sz
= GetClientSize();
1581 bool doDrawFocusRect
; // also selected
1583 // For smaller size control (and for disabled background) use less spacing
1587 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1590 isEnabled
= IsEnabled();
1591 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1593 // Windows-style: for smaller size control (and for disabled background) use less spacing
1594 focusSpacingX
= isEnabled
? 2 : 1;
1595 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1599 // Drawing a list item
1600 isEnabled
= true; // they are never disabled
1601 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1607 // Set the background sub-rectangle for selection, disabled etc
1608 wxRect
selRect(rect
);
1609 selRect
.y
+= focusSpacingY
;
1610 selRect
.height
-= (focusSpacingY
*2);
1614 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1615 wcp
+= m_widthCustomPaint
;
1617 selRect
.x
+= wcp
+ focusSpacingX
;
1618 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1623 bool doDrawSelRect
= true;
1625 // Determine foreground colour
1628 if ( doDrawFocusRect
)
1630 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1632 else if ( m_hasFgCol
)
1634 // Honour the custom foreground colour
1635 fgCol
= GetForegroundColour();
1639 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1644 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1647 // Determine background colour
1650 if ( doDrawFocusRect
)
1652 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1654 else if ( m_hasTcBgCol
)
1656 // Honour the custom background colour
1661 #ifndef __WXMAC__ // see note in OnThemeChange
1662 doDrawSelRect
= false;
1663 bgCol
= GetBackgroundColour();
1665 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1671 #ifndef __WXMAC__ // see note in OnThemeChange
1672 bgCol
= GetBackgroundColour();
1674 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1678 dc
.SetTextForeground( fgCol
);
1679 dc
.SetBrush( bgCol
);
1680 if ( doDrawSelRect
)
1683 dc
.DrawRectangle( selRect
);
1686 // Don't clip exactly to the selection rectangle so we can draw
1687 // to the non-selected area in front of it.
1688 wxRect
clipRect(rect
.x
,rect
.y
,
1689 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1690 dc
.SetClippingRegion(clipRect
);
1693 // Save the library size a bit for platforms that re-implement this.
1694 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1699 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1701 int drawState
= m_btnState
;
1703 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1704 GetPopupWindowState() >= Animating
)
1705 drawState
|= wxCONTROL_PRESSED
;
1707 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1708 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1712 // Make sure area is not larger than the control
1713 if ( drawRect
.y
< rect
.y
)
1714 drawRect
.y
= rect
.y
;
1715 if ( drawRect
.height
> rect
.height
)
1716 drawRect
.height
= rect
.height
;
1718 bool enabled
= IsEnabled();
1721 drawState
|= wxCONTROL_DISABLED
;
1723 // Need to clear button background even if m_btn is present
1724 // and also when using custom bitmap for the button
1725 if ( (flags
& Button_PaintBackground
) &&
1726 (!HasTransparentBackground() ||
1727 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1731 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1732 bgCol
= GetParent()->GetBackgroundColour();
1734 bgCol
= GetBackgroundColour();
1738 dc
.DrawRectangle(rect
);
1741 if ( !m_bmpNormal
.IsOk() )
1743 if ( flags
& Button_BitmapOnly
)
1746 // Draw standard button
1747 wxRendererNative::Get().DrawComboBoxDropButton(this,
1759 pBmp
= &m_bmpDisabled
;
1760 else if ( m_btnState
& wxCONTROL_PRESSED
)
1761 pBmp
= &m_bmpPressed
;
1762 else if ( m_btnState
& wxCONTROL_CURRENT
)
1765 pBmp
= &m_bmpNormal
;
1767 if ( m_blankButtonBg
)
1769 if ( !(flags
& Button_BitmapOnly
) )
1771 wxRendererNative::Get().DrawPushButton(this,
1778 // Draw bitmap centered in drawRect
1779 dc
.DrawBitmap(*pBmp
,
1780 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1781 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1786 void wxComboCtrlBase::RecalcAndRefresh()
1790 wxSizeEvent
evt(GetSize(),GetId());
1791 evt
.SetEventObject(this);
1792 GetEventHandler()->ProcessEvent(evt
);
1797 // ----------------------------------------------------------------------------
1798 // miscellaneous event handlers
1799 // ----------------------------------------------------------------------------
1801 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1803 // Avoid infinite recursion
1804 if ( event
.GetEventObject() == this )
1810 if ( event
.GetEventType() == wxEVT_TEXT
)
1812 if ( m_ignoreEvtText
> 0 )
1819 // For safety, completely re-create a new wxCommandEvent
1820 wxCommandEvent
evt2(event
);
1821 evt2
.SetId(GetId());
1822 evt2
.SetEventObject(this);
1823 HandleWindowEvent(evt2
);
1825 event
.StopPropagation();
1828 // call if cursor is on button area or mouse is captured for the button
1829 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1832 int type
= event
.GetEventType();
1834 if ( type
== wxEVT_MOTION
)
1836 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1837 IsPopupWindowState(Hidden
) )
1839 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1841 // Mouse hover begins
1842 m_btnState
|= wxCONTROL_CURRENT
;
1843 if ( HasCapture() ) // Retain pressed state.
1844 m_btnState
|= wxCONTROL_PRESSED
;
1848 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1851 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1855 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1857 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1859 m_btnState
|= wxCONTROL_PRESSED
;
1862 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1865 // If showing popup now, do not capture mouse or there will be interference
1869 else if ( type
== wxEVT_LEFT_UP
)
1872 // Only accept event if mouse was left-press was previously accepted
1876 if ( m_btnState
& wxCONTROL_PRESSED
)
1878 // If mouse was inside, fire the click event.
1879 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1881 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1885 m_btnState
&= ~(wxCONTROL_PRESSED
);
1889 else if ( type
== wxEVT_LEAVE_WINDOW
)
1891 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1893 m_btnState
&= ~(wxCONTROL_CURRENT
);
1896 if ( IsPopupWindowState(Hidden
) )
1898 m_btnState
&= ~(wxCONTROL_PRESSED
);
1906 // Never have 'hot' state when popup is being shown
1907 // (this is mostly needed because of the animation).
1908 if ( !IsPopupWindowState(Hidden
) )
1909 m_btnState
&= ~wxCONTROL_CURRENT
;
1914 // returns true if event was consumed or filtered
1915 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1916 int WXUNUSED(flags
) )
1918 wxLongLong t
= ::wxGetLocalTimeMillis();
1919 int evtType
= event
.GetEventType();
1921 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1922 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1924 if ( IsPopupWindowState(Visible
) &&
1925 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1933 // Filter out clicks on button immediately after popup dismiss
1934 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1936 event
.SetEventType(0);
1943 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1945 int evtType
= event
.GetEventType();
1947 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1948 (m_windowStyle
& wxCB_READONLY
) )
1950 if ( GetPopupWindowState() >= Animating
)
1952 #if USES_WXPOPUPWINDOW
1953 // Click here always hides the popup.
1954 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1960 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1962 // In read-only mode, clicking the text is the
1963 // same as clicking the button.
1966 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1968 //if ( m_popupInterface->CycleValue() )
1970 if ( m_popupInterface
)
1971 m_popupInterface
->OnComboDoubleClick();
1975 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1977 if ( IsPopupShown() )
1979 // relay (some) mouse events to the popup
1980 m_popup
->GetEventHandler()->ProcessEvent(event
);
1982 else if ( event
.GetWheelAxis() == 0 &&
1983 event
.GetWheelRotation() != 0 &&
1984 event
.GetModifiers() == 0 )
1986 // Translate mousewheel actions into key up/down. This is
1987 // the simplest way of getting native behaviour: scrolling the
1988 // wheel moves selection up/down by one item.
1989 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1990 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1993 GetEventHandler()->ProcessEvent(kevent
);
2006 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
2008 if ( IsPopupShown() )
2010 // pass it to the popped up control
2011 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2015 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2017 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
2019 if ( mainCtrl
->HandleAsNavigationKey(event
) )
2023 if ( IsKeyPopupToggle(event
) )
2029 int comboStyle
= GetWindowStyle();
2030 wxComboPopup
* popupInterface
= GetPopupControl();
2032 if ( !popupInterface
)
2038 int keycode
= event
.GetKeyCode();
2040 if ( (comboStyle
& wxCB_READONLY
) ||
2041 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
2043 popupInterface
->OnComboKeyEvent(event
);
2050 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
2052 if ( IsPopupShown() )
2054 // pass it to the popped up control
2055 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2059 wxComboPopup
* popupInterface
= GetPopupControl();
2060 if ( popupInterface
)
2062 popupInterface
->OnComboCharEvent(event
);
2071 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
2073 // On Mac, setting focus here leads to infinite recursion and eventually
2074 // a crash due to the SetFocus call producing another event.
2075 // Handle Mac in OnIdleEvent using m_resetFocus.
2077 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2079 if ( GetTextCtrl() && !GetTextCtrl()->HasFocus() )
2082 m_resetFocus
= true;
2084 GetTextCtrl()->SetFocus();
2092 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2096 m_resetFocus
= false;
2097 if ( GetTextCtrl() )
2098 GetTextCtrl()->SetFocus();
2102 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2105 // left margin may also have changed
2106 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2107 m_marginLeft
= GetNativeTextIndent();
2111 // ----------------------------------------------------------------------------
2113 // ----------------------------------------------------------------------------
2115 // Create popup window and the child control
2116 void wxComboCtrlBase::CreatePopup()
2118 wxComboPopup
* popupInterface
= m_popupInterface
;
2123 #ifdef wxComboPopupWindowBase2
2124 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2126 #if !USES_GENERICTLW
2127 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2129 int tlwFlags
= wxNO_BORDER
;
2130 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2131 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2134 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2135 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2136 wxPoint(-21,-21), wxSize(20, 20),
2139 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2140 wxPoint(-21,-21), wxSize(20, 20),
2144 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2147 #endif // wxComboPopupWindowBase2
2149 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2150 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2152 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2153 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2156 popupInterface
->Create(m_winPopup
);
2157 m_popup
= popup
= popupInterface
->GetControl();
2159 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2160 popup
->PushEventHandler( m_popupEvtHandler
);
2162 // This may be helpful on some platforms
2163 // (eg. it bypasses a wxGTK popupwindow bug where
2164 // window is not initially hidden when it should be)
2167 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2170 // Destroy popup window and the child control
2171 void wxComboCtrlBase::DestroyPopup()
2176 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2178 wxDELETE(m_popupEvtHandler
);
2180 if ( m_popupInterface
)
2182 // NB: DestroyPopup() performs 'delete this'.
2183 m_popupInterface
->DestroyPopup();
2184 m_popupInterface
= NULL
;
2189 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2190 wxDELETE(m_popupWinEvtHandler
);
2191 m_winPopup
->Destroy();
2198 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2200 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2204 iface
->InitBase(this);
2207 m_popupInterface
= iface
;
2209 if ( !iface
->LazyCreate() )
2218 // This must be done after creation
2219 if ( !m_valueString
.empty() )
2221 iface
->SetStringValue(m_valueString
);
2226 // Ensures there is atleast the default popup
2227 void wxComboCtrlBase::EnsurePopupControl()
2229 if ( !m_popupInterface
)
2230 SetPopupControl(NULL
);
2233 void wxComboCtrlBase::OnButtonClick()
2235 // Derived classes can override this method for totally custom
2237 switch ( GetPopupWindowState() )
2254 void wxComboCtrlBase::Popup()
2256 wxCommandEvent
event(wxEVT_COMBOBOX_DROPDOWN
, GetId());
2257 event
.SetEventObject(this);
2258 HandleWindowEvent(event
);
2263 void wxComboCtrlBase::ShowPopup()
2265 EnsurePopupControl();
2266 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2268 if ( IsPopupWindowState(Animating
) )
2273 // Space above and below
2279 wxSize ctrlSz
= GetSize();
2281 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2282 scrPos
= GetParent()->ClientToScreen(GetPosition());
2284 spaceAbove
= scrPos
.y
;
2285 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2287 maxHeightPopup
= spaceBelow
;
2288 if ( spaceAbove
> spaceBelow
)
2289 maxHeightPopup
= spaceAbove
;
2292 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2294 if ( widthPopup
< m_widthMinPopup
)
2295 widthPopup
= m_widthMinPopup
;
2297 wxWindow
* winPopup
= m_winPopup
;
2300 // Need to disable tab traversal of parent
2302 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2303 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2304 // that if transient popup is open, then tab traversal is to be ignored.
2305 // However, I think this code would still be needed for cases where
2306 // transient popup doesn't work yet (wxWinCE?).
2307 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2308 wxWindow
* parent
= mainCtrl
->GetParent();
2309 int parentFlags
= parent
->GetWindowStyle();
2310 if ( parentFlags
& wxTAB_TRAVERSAL
)
2312 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2313 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2319 winPopup
= m_winPopup
;
2329 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2331 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2332 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2335 popup
->SetSize(adjustedSize
);
2337 m_popupInterface
->OnPopup();
2340 // Reposition and resize popup window
2343 wxSize szp
= popup
->GetSize();
2346 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2348 // Default anchor is wxLEFT
2349 int anchorSide
= m_anchorSide
;
2351 anchorSide
= wxLEFT
;
2353 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2354 int leftX
= scrPos
.x
- m_extLeft
;
2356 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2359 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2361 // If there is not enough horizontal space, anchor on the other side.
2362 // If there is no space even then, place the popup at x 0.
2363 if ( anchorSide
== wxRIGHT
)
2367 if ( (leftX
+szp
.x
) < screenWidth
)
2368 anchorSide
= wxLEFT
;
2375 if ( (leftX
+szp
.x
) >= screenWidth
)
2378 anchorSide
= wxRIGHT
;
2384 // Select x coordinate according to the anchor side
2385 if ( anchorSide
== wxRIGHT
)
2387 else if ( anchorSide
== wxLEFT
)
2392 int showFlags
= CanDeferShow
;
2394 if ( spaceBelow
< szp
.y
)
2396 popupY
= scrPos
.y
- szp
.y
;
2397 showFlags
|= ShowAbove
;
2400 #if INSTALL_TOPLEV_HANDLER
2401 // Put top level window event handler into place
2402 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2404 if ( !m_toplevEvtHandler
)
2405 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2407 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2409 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2410 toplev
->PushEventHandler( m_toplevEvtHandler
);
2414 // Set string selection (must be this way instead of SetStringSelection)
2417 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2418 m_text
->SelectAll();
2420 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2424 // This is neede since focus/selection indication may change when popup is shown
2428 // This must be after SetStringValue
2429 m_popupWinState
= Animating
;
2431 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2434 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2435 AnimateShow( popupWinRect
, showFlags
) )
2437 DoShowPopup( popupWinRect
, showFlags
);
2441 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2446 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2448 wxWindow
* winPopup
= m_winPopup
;
2450 if ( IsPopupWindowState(Animating
) )
2452 // Make sure the popup window is shown in the right position.
2453 // Should not matter even if animation already did this.
2455 // Some platforms (GTK) may like SetSize and Move to be separate
2456 // (though the bug was probably fixed).
2457 winPopup
->SetSize( rect
);
2459 #if USES_WXPOPUPTRANSIENTWINDOW
2460 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2461 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2466 m_popupWinState
= Visible
;
2468 // If popup window was a generic top-level window, or the
2469 // wxPopupWindow implemenation on this platform is classified as
2470 // perfect, then we should be able to safely set focus to the popup
2472 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2473 m_popup
->SetFocus();
2475 else if ( IsPopupWindowState(Hidden
) )
2477 // Animation was aborted
2479 wxASSERT( !winPopup
->IsShown() );
2481 m_popupWinState
= Hidden
;
2487 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2489 // Just in case, avoid double dismiss
2490 if ( IsPopupWindowState(Hidden
) )
2493 // This must be set before focus - otherwise there will be recursive
2494 // OnPopupDismisses.
2495 m_popupWinState
= Hidden
;
2498 m_winPopup
->Disable();
2500 // Inform popup control itself
2501 m_popupInterface
->OnDismiss();
2503 if ( m_popupEvtHandler
)
2504 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2506 #if INSTALL_TOPLEV_HANDLER
2507 // Remove top level window event handler
2508 if ( m_toplevEvtHandler
)
2510 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2512 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2516 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2518 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2519 m_timeCanAcceptClick
+= 150;
2521 // If cursor not on dropdown button, then clear its state
2522 // (technically not required by all ports, but do it for all just in case)
2523 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2526 // Return parent's tab traversal flag.
2527 // See ShowPopup for notes.
2528 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2530 wxWindow
* parent
= GetParent();
2531 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2532 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2535 // refresh control (necessary even if m_text)
2540 if ( generateEvent
)
2542 wxCommandEvent
event(wxEVT_COMBOBOX_CLOSEUP
, GetId());
2543 event
.SetEventObject(this);
2544 HandleWindowEvent(event
);
2548 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2550 // Should be able to call this without popup interface
2551 if ( IsPopupWindowState(Hidden
) )
2554 // transfer value and show it in textctrl, if any
2555 if ( !IsPopupWindowState(Animating
) )
2556 SetValueByUser( m_popupInterface
->GetStringValue() );
2560 OnPopupDismiss(generateEvent
);
2563 // ----------------------------------------------------------------------------
2564 // customization methods
2565 // ----------------------------------------------------------------------------
2567 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2568 int side
, int spacingX
)
2573 m_btnSpacingX
= spacingX
;
2575 if ( width
> 0 || height
> 0 || spacingX
)
2576 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2581 wxSize
wxComboCtrlBase::GetButtonSize()
2583 if ( m_btnSize
.x
> 0 )
2586 wxSize
retSize(m_btnWid
,m_btnHei
);
2588 // Need to call CalculateAreas now if button size is
2589 // is not explicitly specified.
2590 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2594 retSize
= m_btnSize
;
2600 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2602 const wxBitmap
& bmpPressed
,
2603 const wxBitmap
& bmpHover
,
2604 const wxBitmap
& bmpDisabled
)
2606 m_bmpNormal
= bmpNormal
;
2607 m_blankButtonBg
= blankButtonBg
;
2609 if ( bmpPressed
.IsOk() )
2610 m_bmpPressed
= bmpPressed
;
2612 m_bmpPressed
= bmpNormal
;
2614 if ( bmpHover
.IsOk() )
2615 m_bmpHover
= bmpHover
;
2617 m_bmpHover
= bmpNormal
;
2619 if ( bmpDisabled
.IsOk() )
2620 m_bmpDisabled
= bmpDisabled
;
2622 m_bmpDisabled
= bmpNormal
;
2627 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2631 // move textctrl accordingly
2632 wxRect r
= m_text
->GetRect();
2633 int inc
= width
- m_widthCustomPaint
;
2636 m_text
->SetSize( r
);
2639 m_widthCustomPaint
= width
;
2644 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2646 // For general sanity's sake, we ignore top margin. Instead
2647 // we will always try to center the text vertically.
2650 if ( margins
.x
!= -1 )
2652 m_marginLeft
= margins
.x
;
2653 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2657 m_marginLeft
= GetNativeTextIndent();
2658 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2661 if ( margins
.y
!= -1 )
2671 wxPoint
wxComboCtrlBase::DoGetMargins() const
2673 return wxPoint(m_marginLeft
, -1);
2676 #if WXWIN_COMPATIBILITY_2_8
2677 void wxComboCtrlBase::SetTextIndent( int indent
)
2681 m_marginLeft
= GetNativeTextIndent();
2682 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2686 m_marginLeft
= indent
;
2687 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2693 wxCoord
wxComboCtrlBase::GetTextIndent() const
2695 return m_marginLeft
;
2699 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2701 return DEFAULT_TEXT_INDENT
;
2704 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2706 m_textCtrlStyle
= style
;
2709 m_text
->SetWindowStyle(style
);
2712 // ----------------------------------------------------------------------------
2713 // wxTextEntry interface
2714 // ----------------------------------------------------------------------------
2716 wxString
wxComboCtrlBase::DoGetValue() const
2719 return m_text
->GetValue();
2720 return m_valueString
;
2723 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2726 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2729 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2731 // Note: before wxComboCtrl inherited from wxTextEntry,
2732 // this code used to be in SetValueWithEvent().
2734 // Since wxComboPopup may want to paint the combo as well, we need
2735 // to set the string value here (as well as sometimes in ShowPopup).
2736 if ( m_valueString
!= value
)
2739 wxString trueValue
= value
;
2741 // Conform to wxComboBox behaviour: read-only control can only accept
2742 // valid list items and empty string
2743 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2745 found
= m_popupInterface
->FindItem(value
,
2751 m_valueString
= trueValue
;
2753 EnsurePopupControl();
2755 if ( m_popupInterface
)
2756 m_popupInterface
->SetStringValue(trueValue
);
2763 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2765 // NB: Order of function calls is important here. Otherwise
2766 // the SelectAll() may not work.
2770 m_text
->SetValue(value
);
2772 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2773 m_text
->SelectAll();
2779 // In this SetValue variant wxComboPopup::SetStringValue is not called
2780 void wxComboCtrlBase::SetText(const wxString
& value
)
2782 // Unlike in SetValue(), this must be called here or
2783 // the behaviour will no be consistent in readonlys.
2784 EnsurePopupControl();
2786 m_valueString
= value
;
2791 m_text
->SetValue( value
);
2797 void wxComboCtrlBase::Copy()
2803 void wxComboCtrlBase::Cut()
2809 void wxComboCtrlBase::Paste()
2815 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2818 m_text
->SetInsertionPoint(pos
);
2821 long wxComboCtrlBase::GetInsertionPoint() const
2824 return m_text
->GetInsertionPoint();
2829 long wxComboCtrlBase::GetLastPosition() const
2832 return m_text
->GetLastPosition();
2837 void wxComboCtrlBase::WriteText(const wxString
& text
)
2841 m_text
->WriteText(text
);
2842 OnSetValue(m_text
->GetValue());
2850 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2854 if ( flags
& SetValue_SendEvent
)
2855 m_text
->SetValue(value
);
2857 m_text
->ChangeValue(value
);
2863 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2867 m_text
->Replace(from
, to
, value
);
2868 OnSetValue(m_text
->GetValue());
2872 void wxComboCtrlBase::Remove(long from
, long to
)
2876 m_text
->Remove(from
, to
);
2877 OnSetValue(m_text
->GetValue());
2881 void wxComboCtrlBase::SetSelection(long from
, long to
)
2884 m_text
->SetSelection(from
, to
);
2887 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2891 m_text
->GetSelection(from
, to
);
2900 bool wxComboCtrlBase::IsEditable() const
2903 return m_text
->IsEditable();
2907 void wxComboCtrlBase::SetEditable(bool editable
)
2910 m_text
->SetEditable(editable
);
2913 void wxComboCtrlBase::Undo()
2919 void wxComboCtrlBase::Redo()
2925 bool wxComboCtrlBase::CanUndo() const
2928 return m_text
->CanUndo();
2933 bool wxComboCtrlBase::CanRedo() const
2936 return m_text
->CanRedo();
2941 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2946 res
= m_text
->SetHint(hint
);
2951 wxString
wxComboCtrlBase::GetHint() const
2956 #endif // wxUSE_COMBOCTRL