1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/combobox.h"
33 #include "wx/dcclient.h"
34 #include "wx/settings.h"
36 #include "wx/textctrl.h"
39 #include "wx/tooltip.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 wxDEFINE_FLAGS( wxComboBoxStyle
)
49 wxBEGIN_FLAGS( wxComboBoxStyle
)
50 // new style border flags, we put them first to
51 // use them for streaming out
52 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
53 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
54 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
55 wxFLAGS_MEMBER(wxBORDER_RAISED
)
56 wxFLAGS_MEMBER(wxBORDER_STATIC
)
57 wxFLAGS_MEMBER(wxBORDER_NONE
)
59 // old style border flags
60 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
61 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
62 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
63 wxFLAGS_MEMBER(wxRAISED_BORDER
)
64 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
65 wxFLAGS_MEMBER(wxBORDER
)
67 // standard window styles
68 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
69 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
70 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
71 wxFLAGS_MEMBER(wxWANTS_CHARS
)
72 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
73 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
74 wxFLAGS_MEMBER(wxVSCROLL
)
75 wxFLAGS_MEMBER(wxHSCROLL
)
77 wxFLAGS_MEMBER(wxCB_SIMPLE
)
78 wxFLAGS_MEMBER(wxCB_SORT
)
79 wxFLAGS_MEMBER(wxCB_READONLY
)
80 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
82 wxEND_FLAGS( wxComboBoxStyle
)
84 #ifdef __WXUNIVERSAL__
85 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
87 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxChoice
, "wx/combobox.h")
90 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
91 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
)
92 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
95 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
96 0 /*flags*/, wxT("Helpstring"), wxT("group"))
97 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
98 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
99 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
100 0 /*flags*/, wxT("Helpstring"), wxT("group"))
101 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
102 0 /*flags*/, wxT("Helpstring"), wxT("group"))
104 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
105 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
106 wxT("Helpstring"), wxT("group")) // style
107 wxEND_PROPERTIES_TABLE()
109 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
111 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
112 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
115 // ----------------------------------------------------------------------------
117 #define DEFAULT_DROPBUTTON_WIDTH 19
119 #define BMP_BUTTON_MARGIN 4
121 #define DEFAULT_POPUP_HEIGHT 400
123 #define DEFAULT_TEXT_INDENT 3
125 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
128 #if defined(__WXMSW__)
130 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
131 #include "wx/frame.h"
132 #define wxCC_GENERIC_TLW_IS_FRAME
133 #define wxComboCtrlGenericTLW wxFrame
135 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
136 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
137 // native controls work on it like normal.
138 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
139 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
140 #define FOCUS_RING 0 // No focus ring on wxMSW
142 //#undef wxUSE_POPUPWIN
143 //#define wxUSE_POPUPWIN 0
145 #elif defined(__WXGTK__)
147 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
148 // this bug: If wxDialog is hidden, its position becomes corrupt
149 // between hide and next show, but without internal coordinates being
150 // reflected (or something like that - atleast commenting out ->Hide()
151 // seemed to eliminate the position change).
153 #include "wx/dialog.h"
154 #define wxCC_GENERIC_TLW_IS_DIALOG
155 #define wxComboCtrlGenericTLW wxDialog
157 #if defined(__WXGTK20__)
158 # include "wx/gtk/private.h"
160 # include "wx/gtk1/private.h"
163 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
164 // 'perfect' popup, as it can succesfully host child controls even in
165 // popups that are shown in modal dialogs.
167 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
168 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
169 // native controls work on it like normal.
170 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
171 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
172 #define FOCUS_RING 0 // No focus ring on wxGTK
174 #elif defined(__WXMAC__)
176 #include "wx/nonownedwnd.h"
177 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
178 #define wxComboCtrlGenericTLW wxNonOwnedWindow
180 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
181 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
182 // native controls work on it like normal.
183 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
184 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
185 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
187 #undef DEFAULT_DROPBUTTON_WIDTH
188 #define DEFAULT_DROPBUTTON_WIDTH 22
190 #define COMBO_MARGIN FOCUS_RING
194 #include "wx/dialog.h"
195 #define wxCC_GENERIC_TLW_IS_DIALOG
196 #define wxComboCtrlGenericTLW wxDialog
198 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
199 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
200 // native controls work on it like normal.
201 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
202 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
208 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
209 // what the wxUSE_POPUPWIN says.
210 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
211 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
212 #undef wxUSE_POPUPWIN
213 #define wxUSE_POPUPWIN 0
218 #include "wx/popupwin.h"
220 #undef USE_TRANSIENT_POPUP
221 #define USE_TRANSIENT_POPUP 0
225 // Define different types of popup windows
229 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
230 POPUPWIN_WXPOPUPWINDOW
= 2,
231 POPUPWIN_GENERICTLW
= 3
235 #if USE_TRANSIENT_POPUP
236 // wxPopupTransientWindow is implemented
238 #define wxComboPopupWindowBase wxPopupTransientWindow
239 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
240 #define USES_WXPOPUPTRANSIENTWINDOW 1
242 #if TRANSIENT_POPUPWIN_IS_PERFECT
244 #elif POPUPWIN_IS_PERFECT
245 #define wxComboPopupWindowBase2 wxPopupWindow
246 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
247 #define USES_WXPOPUPWINDOW 1
249 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
250 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
251 #define USES_GENERICTLW 1
255 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
257 #define wxComboPopupWindowBase wxPopupWindow
258 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
259 #define USES_WXPOPUPWINDOW 1
261 #if !POPUPWIN_IS_PERFECT
262 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
263 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
264 #define USES_GENERICTLW 1
268 // wxPopupWindow is not implemented
270 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
271 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
272 #define USES_GENERICTLW 1
277 #ifndef USES_WXPOPUPTRANSIENTWINDOW
278 #define USES_WXPOPUPTRANSIENTWINDOW 0
281 #ifndef USES_WXPOPUPWINDOW
282 #define USES_WXPOPUPWINDOW 0
285 #ifndef USES_GENERICTLW
286 #define USES_GENERICTLW 0
290 #if USES_WXPOPUPWINDOW
291 #define INSTALL_TOPLEV_HANDLER 1
293 #define INSTALL_TOPLEV_HANDLER 0
297 // Returns true if given popup window type can be classified as perfect
299 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
301 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
302 wxUnusedVar(popupWinType
);
305 return ( popupWinType
== POPUPWIN_GENERICTLW
306 #if POPUPWIN_IS_PERFECT
307 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
309 #if TRANSIENT_POPUPWIN_IS_PERFECT
310 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
319 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
323 // ----------------------------------------------------------------------------
324 // wxComboFrameEventHandler takes care of hiding the popup when events happen
325 // in its top level parent.
326 // ----------------------------------------------------------------------------
328 #if INSTALL_TOPLEV_HANDLER
331 // This will no longer be necessary after wxTransientPopupWindow
332 // works well on all platforms.
335 class wxComboFrameEventHandler
: public wxEvtHandler
338 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
339 virtual ~wxComboFrameEventHandler();
343 void OnIdle( wxIdleEvent
& event
);
344 void OnMouseEvent( wxMouseEvent
& event
);
345 void OnActivate( wxActivateEvent
& event
);
346 void OnResize( wxSizeEvent
& event
);
347 void OnMove( wxMoveEvent
& event
);
348 void OnMenuEvent( wxMenuEvent
& event
);
349 void OnClose( wxCloseEvent
& event
);
352 wxWindow
* m_focusStart
;
353 wxComboCtrlBase
* m_combo
;
356 DECLARE_EVENT_TABLE()
359 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
360 EVT_IDLE(wxComboFrameEventHandler
::OnIdle
)
361 EVT_LEFT_DOWN(wxComboFrameEventHandler
::OnMouseEvent
)
362 EVT_RIGHT_DOWN(wxComboFrameEventHandler
::OnMouseEvent
)
363 EVT_SIZE(wxComboFrameEventHandler
::OnResize
)
364 EVT_MOVE(wxComboFrameEventHandler
::OnMove
)
365 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler
::OnMenuEvent
)
366 EVT_MENU_OPEN(wxComboFrameEventHandler
::OnMenuEvent
)
367 EVT_ACTIVATE(wxComboFrameEventHandler
::OnActivate
)
368 EVT_CLOSE(wxComboFrameEventHandler
::OnClose
)
371 wxComboFrameEventHandler
::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
377 wxComboFrameEventHandler
::~wxComboFrameEventHandler()
381 void wxComboFrameEventHandler
::OnPopup()
383 m_focusStart
= ::wxWindow
::FindFocus();
386 void wxComboFrameEventHandler
::OnIdle( wxIdleEvent
& event
)
388 wxWindow
* winFocused
= ::wxWindow
::FindFocus();
390 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
391 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
394 winFocused
!= m_focusStart
&&
395 winFocused
!= popup
&&
396 winFocused
->GetParent() != popup
&&
397 winFocused
!= winpopup
&&
398 winFocused
->GetParent() != winpopup
&&
399 winFocused
!= m_combo
&&
400 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 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
495 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
497 if ( show
!= ptw
->IsShown() )
500 // We used to do wxPopupTransientWindow::Popup here,
501 // but this would hide normal Show, which we are
502 // also going to need.
513 bool wxComboPopupWindow
::ProcessLeftDown(wxMouseEvent
& event
)
515 return wxPopupTransientWindow
::ProcessLeftDown(event
);
518 // First thing that happens when a transient popup closes is that this method gets called.
519 void wxComboPopupWindow
::OnDismiss()
521 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
522 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
523 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
525 combo
->OnPopupDismiss(true);
527 #endif // USES_WXPOPUPTRANSIENTWINDOW
530 // ----------------------------------------------------------------------------
531 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
532 // of a popup window. It is separate so we can have different types
534 // ----------------------------------------------------------------------------
536 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
540 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
545 void OnSizeEvent( wxSizeEvent
& event
);
546 void OnKeyEvent(wxKeyEvent
& event
);
548 void OnActivate( wxActivateEvent
& event
);
552 wxComboCtrlBase
* m_combo
;
554 DECLARE_EVENT_TABLE()
558 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
559 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler
::OnKeyEvent
)
560 EVT_KEY_UP(wxComboPopupWindowEvtHandler
::OnKeyEvent
)
561 EVT_CHAR(wxComboPopupWindowEvtHandler
::OnKeyEvent
)
563 EVT_ACTIVATE(wxComboPopupWindowEvtHandler
::OnActivate
)
565 EVT_SIZE(wxComboPopupWindowEvtHandler
::OnSizeEvent
)
569 void wxComboPopupWindowEvtHandler
::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
571 // Block the event so that the popup control does not get auto-resized.
574 void wxComboPopupWindowEvtHandler
::OnKeyEvent( wxKeyEvent
& event
)
576 // Relay keyboard event to the main child controls
577 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
578 wxWindowList
::iterator node
= children
.begin();
579 wxWindow
* child
= (wxWindow
*)*node
;
580 child
->GetEventHandler()->ProcessEvent(event
);
584 void wxComboPopupWindowEvtHandler
::OnActivate( wxActivateEvent
& event
)
586 if ( !event
.GetActive() )
588 // Tell combo control that we are dismissed.
589 m_combo
->HidePopup(true);
597 // ----------------------------------------------------------------------------
600 // ----------------------------------------------------------------------------
602 wxComboPopup
::~wxComboPopup()
606 void wxComboPopup
::OnPopup()
610 void wxComboPopup
::OnDismiss()
614 wxComboCtrl
* wxComboPopup
::GetComboCtrl() const
616 return wxStaticCast(m_combo
, wxComboCtrl
);
619 wxSize wxComboPopup
::GetAdjustedSize( int minWidth
,
621 int WXUNUSED(maxHeight
) )
623 return wxSize(minWidth
,prefHeight
);
626 void wxComboPopup
::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
627 wxDC
& dc
, const wxRect
& rect
)
629 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
631 combo
->PrepareBackground(dc
,rect
,0);
633 dc
.DrawText( combo
->GetValue(),
634 rect
.x
+ combo
->m_marginLeft
,
635 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
639 void wxComboPopup
::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
641 DefaultPaintComboControl(m_combo
,dc
,rect
);
644 void wxComboPopup
::OnComboKeyEvent( wxKeyEvent
& event
)
649 void wxComboPopup
::OnComboCharEvent( wxKeyEvent
& event
)
654 void wxComboPopup
::OnComboDoubleClick()
658 void wxComboPopup
::SetStringValue( const wxString
& WXUNUSED(value
) )
662 bool wxComboPopup
::FindItem(const wxString
& WXUNUSED(item
),
663 wxString
* WXUNUSED(trueItem
))
668 bool wxComboPopup
::LazyCreate()
673 void wxComboPopup
::Dismiss()
675 m_combo
->HidePopup(true);
678 // ----------------------------------------------------------------------------
680 // ----------------------------------------------------------------------------
683 // This is pushed to the event handler queue of the child textctrl.
685 class wxComboBoxExtraInputHandler
: public wxEvtHandler
689 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
694 virtual ~wxComboBoxExtraInputHandler() { }
695 void OnKey(wxKeyEvent
& event
);
696 void OnFocus(wxFocusEvent
& event
);
699 wxComboCtrlBase
* m_combo
;
702 DECLARE_EVENT_TABLE()
706 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
707 EVT_KEY_DOWN(wxComboBoxExtraInputHandler
::OnKey
)
708 EVT_KEY_UP(wxComboBoxExtraInputHandler
::OnKey
)
709 EVT_CHAR(wxComboBoxExtraInputHandler
::OnKey
)
710 EVT_SET_FOCUS(wxComboBoxExtraInputHandler
::OnFocus
)
711 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler
::OnFocus
)
715 void wxComboBoxExtraInputHandler
::OnKey(wxKeyEvent
& event
)
717 // Let the wxComboCtrl event handler have a go first.
718 wxComboCtrlBase
* combo
= m_combo
;
720 wxKeyEvent
redirectedEvent(event
);
721 redirectedEvent
.SetId(combo
->GetId());
722 redirectedEvent
.SetEventObject(combo
);
724 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
726 // Don't let TAB through to the text ctrl - looks ugly
727 if ( event
.GetKeyCode() != WXK_TAB
)
732 void wxComboBoxExtraInputHandler
::OnFocus(wxFocusEvent
& event
)
734 // FIXME: This code does run when control is clicked,
735 // yet on Windows it doesn't select all the text.
736 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
737 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
739 if ( m_combo
->GetTextCtrl() )
740 m_combo
->GetTextCtrl()->SelectAll();
742 m_combo
->SetSelection(-1,-1);
745 // Send focus indication to parent.
746 // NB: This is needed for cases where the textctrl gets focus
747 // instead of its parent. While this may trigger multiple
748 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
749 // from combo's focus event handler), they should be quite
751 wxFocusEvent
evt2(event
);
752 evt2
.SetId(m_combo
->GetId());
753 evt2
.SetEventObject(m_combo
);
754 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
761 // This is pushed to the event handler queue of the control in popup.
764 class wxComboPopupEvtHandler
: public wxEvtHandler
768 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
772 m_beenInside
= false;
774 // Let's make it so that the popup control will not receive mouse
775 // events until mouse left button has been up.
776 m_blockEventsToPopup
= true;
778 virtual ~wxComboPopupEvtHandler() { }
780 void OnMouseEvent( wxMouseEvent
& event
);
782 // Called from wxComboCtrlBase::OnPopupDismiss
783 void OnPopupDismiss()
785 m_beenInside
= false;
786 m_blockEventsToPopup
= true;
790 wxComboCtrlBase
* m_combo
;
793 bool m_blockEventsToPopup
;
796 DECLARE_EVENT_TABLE()
800 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
801 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler
::OnMouseEvent
)
805 void wxComboPopupEvtHandler
::OnMouseEvent( wxMouseEvent
& event
)
807 wxPoint pt
= event
.GetPosition();
808 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
809 int evtType
= event
.GetEventType();
810 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
811 bool relayToButton
= false;
815 if ( !isInside
|| !m_combo
->IsPopupShown() )
817 // Mouse is outside the popup or popup is not actually shown (yet)
819 if ( evtType
== wxEVT_MOTION
||
820 evtType
== wxEVT_LEFT_DOWN
||
821 evtType
== wxEVT_LEFT_UP
||
822 evtType
== wxEVT_RIGHT_DOWN
)
824 // Block motion and click events outside the popup
830 // Mouse is inside the popup, which is fully shown
834 // Do not let the popup control respond to mouse events until
835 // mouse press used to display the popup has been lifted. This
836 // is important for users with slower mouse fingers or mouse
837 // drivers. Note that we have some redundancy here, just in
838 // case the popup is some native control that does not emit all
839 // mouse event types.
840 if ( evtType
== wxEVT_MOTION
)
842 if ( m_blockEventsToPopup
)
844 if ( event
.LeftIsDown() )
847 m_blockEventsToPopup
= false;
850 else if ( evtType
== wxEVT_LEFT_DOWN
)
852 if ( m_blockEventsToPopup
)
853 m_blockEventsToPopup
= false;
855 else if ( evtType
== wxEVT_LEFT_UP
)
857 if ( m_blockEventsToPopup
)
859 // On first left up, stop blocking mouse events (but still
861 m_blockEventsToPopup
= false;
864 // Also, this button press was (probably) used to display
865 // the popup, so relay it back to the drop-down button
866 // (which supposedly originated it). This is necessary to
867 // refresh it properly.
868 relayToButton
= true;
871 else if ( m_blockEventsToPopup
)
878 // Some mouse events to popup that happen outside it, before cursor
879 // has been inside the popup, need to be ignored by it but relayed to
882 if ( evtType
== wxEVT_LEFT_UP
)
884 if ( !m_combo
->IsPopupShown() )
887 relayToButton
= true;
889 else if ( !isInside
&& !m_beenInside
)
891 // Popup is shown but the cursor is not inside, nor it has been
892 relayToButton
= true;
898 wxWindow
* btn
= m_combo
->GetButton();
900 btn
->GetEventHandler()->ProcessEvent(event
);
902 // Bypass the event handling mechanism. Using it would be
903 // confusing for the platform-specific wxComboCtrl
905 m_combo
->HandleButtonMouseEvent(event
, 0);
909 // ----------------------------------------------------------------------------
910 // wxComboCtrlTextCtrl
911 // ----------------------------------------------------------------------------
913 class wxComboCtrlTextCtrl
: public wxTextCtrl
916 wxComboCtrlTextCtrl() : wxTextCtrl() { }
917 virtual ~wxComboCtrlTextCtrl() { }
919 virtual wxWindow
*GetMainWindowOfCompositeControl()
921 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
923 // Returning this instead of just 'parent' lets FindFocus work
924 // correctly even when parent control is a child of a composite
925 // generic control (as is case with wxGenericDatePickerCtrl).
926 return combo
->GetMainWindowOfCompositeControl();
930 // ----------------------------------------------------------------------------
932 // ----------------------------------------------------------------------------
935 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
936 EVT_TEXT(wxID_ANY
,wxComboCtrlBase
::OnTextCtrlEvent
)
937 EVT_SIZE(wxComboCtrlBase
::OnSizeEvent
)
938 EVT_SET_FOCUS(wxComboCtrlBase
::OnFocusEvent
)
939 EVT_KILL_FOCUS(wxComboCtrlBase
::OnFocusEvent
)
940 EVT_IDLE(wxComboCtrlBase
::OnIdleEvent
)
941 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
942 EVT_KEY_DOWN(wxComboCtrlBase
::OnKeyEvent
)
943 EVT_CHAR(wxComboCtrlBase
::OnCharEvent
)
944 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase
::OnTextCtrlEvent
)
945 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase
::OnSysColourChanged
)
949 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
951 void wxComboCtrlBase
::Init()
955 m_popupWinState
= Hidden
;
958 m_popupInterface
= NULL
;
960 m_popupEvtHandler
= NULL
;
961 m_textEvtHandler
= NULL
;
963 #if INSTALL_TOPLEV_HANDLER
964 m_toplevEvtHandler
= NULL
;
967 m_mainCtrlWnd
= this;
970 m_widthMinPopup
= -1;
972 m_widthCustomPaint
= 0;
973 m_widthCustomBorder
= 0;
977 m_blankButtonBg
= false;
979 m_popupWinType
= POPUPWIN_NONE
;
980 m_btnWid
= m_btnHei
= -1;
989 m_timeCanAcceptClick
= 0;
991 m_resetFocus
= false;
994 bool wxComboCtrlBase
::Create(wxWindow
*parent
,
996 const wxString
& value
,
1000 const wxValidator
& validator
,
1001 const wxString
& name
)
1003 if ( !wxControl
::Create(parent
,
1007 style
| wxWANTS_CHARS
,
1012 m_valueString
= value
;
1016 m_marginLeft
= GetNativeTextIndent();
1018 m_iFlags
|= wxCC_IFLAG_CREATED
;
1020 // If x and y indicate valid size, wxSizeEvent won't be
1021 // emitted automatically, so we need to add artifical one.
1022 if ( size
.x
> 0 && size
.y
> 0 )
1024 wxSizeEvent
evt(size
,GetId());
1025 GetEventHandler()->AddPendingEvent(evt
);
1031 void wxComboCtrlBase
::InstallInputHandlers()
1035 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1036 m_text
->PushEventHandler(m_textEvtHandler
);
1041 wxComboCtrlBase
::CreateTextCtrl(int style
)
1043 if ( !(m_windowStyle
& wxCB_READONLY
) )
1048 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1049 // not used by the wxPropertyGrid and therefore the tab is processed by
1050 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1051 // navigation event is then sent to the wrong window.
1052 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1054 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1055 style
|= wxTE_PROCESS_ENTER
;
1057 // Ignore EVT_TEXT generated by the constructor (but only
1058 // if the event redirector already exists)
1059 // NB: This must be " = 1" instead of "++";
1060 if ( m_textEvtHandler
)
1061 m_ignoreEvtText
= 1;
1063 m_ignoreEvtText
= 0;
1065 m_text
= new wxComboCtrlTextCtrl();
1066 m_text
->Create(this, wxID_ANY
, m_valueString
,
1067 wxDefaultPosition
, wxSize(10,-1),
1069 m_text
->SetHint(m_hintText
);
1073 void wxComboCtrlBase
::OnThemeChange()
1075 // Leave the default bg on the Mac so the area used by the focus ring will
1076 // be the correct colour and themed brush. Instead we'll use
1077 // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
1079 #if defined(__WXMSW__) || defined(__WXGTK__)
1080 wxVisualAttributes vattrs
= wxComboBox
::GetClassDefaultAttributes();
1082 wxVisualAttributes vattrs
;
1083 vattrs
.colFg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1084 vattrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1087 // Only change the colours if application has not specified
1091 SetOwnForegroundColour(vattrs
.colFg
);
1096 SetOwnBackgroundColour(vattrs
.colBg
);
1099 #endif // !__WXMAC__
1102 wxComboCtrlBase
::~wxComboCtrlBase()
1107 #if INSTALL_TOPLEV_HANDLER
1108 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1109 m_toplevEvtHandler
= NULL
;
1115 m_text
->RemoveEventHandler(m_textEvtHandler
);
1117 delete m_textEvtHandler
;
1121 // ----------------------------------------------------------------------------
1123 // ----------------------------------------------------------------------------
1125 // Recalculates button and textctrl areas
1126 void wxComboCtrlBase
::CalculateAreas( int btnWidth
)
1128 wxSize sz
= GetClientSize();
1129 int customBorder
= m_widthCustomBorder
;
1130 int btnBorder
; // border for button only
1132 // check if button should really be outside the border: we'll do it it if
1133 // its platform default or bitmap+pushbutton background is used, but not if
1134 // there is vertical size adjustment or horizontal spacing.
1135 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1136 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
1137 m_btnSpacingX
== 0 &&
1140 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1143 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1144 m_btnSpacingX
== 0 && !m_bmpNormal
.Ok() )
1146 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1151 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1152 btnBorder
= customBorder
;
1155 // Defaul indentation
1156 if ( m_marginLeft
< 0 )
1157 m_marginLeft
= GetNativeTextIndent();
1159 int butWidth
= btnWidth
;
1161 if ( butWidth
<= 0 )
1162 butWidth
= m_btnWidDefault
;
1164 m_btnWidDefault
= butWidth
;
1166 if ( butWidth
<= 0 )
1169 int butHeight
= sz
.y
- btnBorder
*2;
1171 // Adjust button width
1173 butWidth
= m_btnWid
;
1176 // Adjust button width to match aspect ratio
1177 // (but only if control is smaller than best size).
1178 int bestHeight
= GetBestSize().y
;
1179 int height
= GetSize().y
;
1181 if ( height
< bestHeight
)
1183 // Make very small buttons square, as it makes
1184 // them accommodate arrow image better and still
1187 butWidth
= (height
*butWidth
)/bestHeight
;
1189 butWidth
= butHeight
;
1193 // Adjust button height
1195 butHeight
= m_btnHei
;
1197 // Use size of normal bitmap if...
1200 // button width is set to default and blank button bg is not drawn
1201 if ( m_bmpNormal
.Ok() )
1203 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1204 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1206 // If drawing blank button background, we need to add some margin.
1207 if ( m_blankButtonBg
)
1209 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1210 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1213 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1214 butWidth
= bmpReqWidth
;
1215 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1216 butHeight
= bmpReqHeight
;
1218 // Need to fix height?
1219 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1221 int newY
= butHeight
+(customBorder
*2);
1222 SetClientSize(wxDefaultCoord
,newY
);
1223 if ( m_bmpNormal
.Ok() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1224 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1226 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1232 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1234 m_btnSize
.x
= butWidth
;
1235 m_btnSize
.y
= butHeight
;
1237 m_btnArea
.x
= ( m_btnSide
==wxRIGHT ? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1238 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1239 m_btnArea
.width
= butAreaWid
;
1240 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1242 m_tcArea
.x
= ( m_btnSide
==wxRIGHT ?
0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1243 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1244 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1245 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1250 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1251 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1256 void wxComboCtrlBase
::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1261 wxSize sz
= GetClientSize();
1263 int customBorder
= m_widthCustomBorder
;
1264 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1268 if ( !m_widthCustomPaint
)
1270 // No special custom paint area - we can use 0 left margin
1272 if ( m_text
->SetMargins(0) )
1273 textCtrlXAdjust
= 0;
1274 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1278 // There is special custom paint area - it is better to
1279 // use some margin with the wxTextCtrl.
1280 m_text
->SetMargins(m_marginLeft
);
1281 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1282 m_marginLeft
+ textCtrlXAdjust
;
1285 // Centre textctrl vertically, if needed
1286 #if !TEXTCTRL_TEXT_CENTERED
1287 int tcSizeY
= m_text
->GetBestSize().y
;
1288 int diff0
= sz
.y
- tcSizeY
;
1289 int y
= textCtrlYAdjust
+ (diff0
/2);
1291 wxUnusedVar(textCtrlYAdjust
);
1295 if ( y
< customBorder
)
1300 m_tcArea
.width
- m_tcArea
.x
- x
,
1303 // Make sure textctrl doesn't exceed the bottom custom border
1304 wxSize tsz
= m_text
->GetSize();
1305 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1308 tsz
.y
= tsz
.y
- diff1
- 1;
1309 m_text
->SetSize(tsz
);
1314 // If it has border, have textctrl fill the entire text field.
1315 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1317 m_tcArea
.width
- m_widthCustomPaint
,
1322 wxSize wxComboCtrlBase
::DoGetBestSize() const
1324 wxSize
sizeText(150,0);
1327 sizeText
= m_text
->GetBestSize();
1329 // TODO: Better method to calculate close-to-native control height.
1333 fhei
= (m_font
.GetPointSize()*2) + 5;
1334 else if ( wxNORMAL_FONT
->Ok() )
1335 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1337 fhei
= sizeText
.y
+ 4;
1339 // Need to force height to accomodate bitmap?
1340 int btnSizeY
= m_btnSize
.y
;
1341 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1344 // Control height doesn't depend on border
1347 int border = m_windowStyle & wxBORDER_MASK;
1348 if ( border == wxSIMPLE_BORDER )
1350 else if ( border == wxNO_BORDER )
1351 fhei += (m_widthCustomBorder*2);
1357 // Final adjustments
1363 // these are the numbers from the HIG:
1364 switch ( m_windowVariant
)
1366 case wxWINDOW_VARIANT_NORMAL
:
1370 case wxWINDOW_VARIANT_SMALL
:
1373 case wxWINDOW_VARIANT_MINI
:
1379 fhei
+= 2 * FOCUS_RING
;
1380 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1382 wxSize
ret(width
, fhei
);
1387 void wxComboCtrlBase
::OnSizeEvent( wxSizeEvent
& event
)
1392 // defined by actual wxComboCtrls
1398 // ----------------------------------------------------------------------------
1399 // standard operations
1400 // ----------------------------------------------------------------------------
1402 bool wxComboCtrlBase
::Enable(bool enable
)
1404 if ( !wxControl
::Enable(enable
) )
1408 m_btn
->Enable(enable
);
1410 m_text
->Enable(enable
);
1417 bool wxComboCtrlBase
::Show(bool show
)
1419 if ( !wxControl
::Show(show
) )
1431 bool wxComboCtrlBase
::SetFont ( const wxFont
& font
)
1433 if ( !wxControl
::SetFont(font
) )
1438 // Without hiding the wxTextCtrl there would be some
1439 // visible 'flicker' (at least on Windows XP).
1441 m_text
->SetFont(font
);
1450 void wxComboCtrlBase
::DoSetToolTip(wxToolTip
*tooltip
)
1452 wxControl
::DoSetToolTip(tooltip
);
1454 // Set tool tip for button and text box
1457 const wxString
&tip
= tooltip
->GetTip();
1458 if ( m_text
) m_text
->SetToolTip(tip
);
1459 if ( m_btn
) m_btn
->SetToolTip(tip
);
1463 if ( m_text
) m_text
->SetToolTip( NULL
);
1464 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1467 #endif // wxUSE_TOOLTIPS
1469 bool wxComboCtrlBase
::SetForegroundColour(const wxColour
& colour
)
1471 if ( wxControl
::SetForegroundColour(colour
) )
1474 m_text
->SetForegroundColour(colour
);
1480 bool wxComboCtrlBase
::SetBackgroundColour(const wxColour
& colour
)
1482 if ( wxControl
::SetBackgroundColour(colour
) )
1485 m_text
->SetBackgroundColour(colour
);
1490 // ----------------------------------------------------------------------------
1492 // ----------------------------------------------------------------------------
1494 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1495 // prepare combo box background on area in a way typical on platform
1496 void wxComboCtrlBase
::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1498 wxSize sz
= GetClientSize();
1500 bool doDrawFocusRect
; // also selected
1502 // For smaller size control (and for disabled background) use less spacing
1506 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1509 isEnabled
= IsEnabled();
1510 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1512 // Windows-style: for smaller size control (and for disabled background) use less spacing
1513 focusSpacingX
= isEnabled ?
2 : 1;
1514 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled ?
2 : 1;
1518 // Drawing a list item
1519 isEnabled
= true; // they are never disabled
1520 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1526 // Set the background sub-rectangle for selection, disabled etc
1527 wxRect
selRect(rect
);
1528 selRect
.y
+= focusSpacingY
;
1529 selRect
.height
-= (focusSpacingY
*2);
1533 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1534 wcp
+= m_widthCustomPaint
;
1536 selRect
.x
+= wcp
+ focusSpacingX
;
1537 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1542 bool doDrawSelRect
= true;
1544 // Determine foreground colour
1547 if ( doDrawFocusRect
)
1549 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1551 else if ( m_hasFgCol
)
1553 // Honour the custom foreground colour
1554 fgCol
= GetForegroundColour();
1558 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1563 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1566 // Determine background colour
1569 if ( doDrawFocusRect
)
1571 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1573 else if ( m_hasBgCol
)
1575 // Honour the custom background colour
1576 bgCol
= GetBackgroundColour();
1580 #ifndef __WXMAC__ // see note in OnThemeChange
1581 doDrawSelRect
= false;
1582 bgCol
= GetBackgroundColour();
1584 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1590 #ifndef __WXMAC__ // see note in OnThemeChange
1591 bgCol
= GetBackgroundColour();
1593 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1597 dc
.SetTextForeground( fgCol
);
1598 dc
.SetBrush( bgCol
);
1599 if ( doDrawSelRect
)
1602 dc
.DrawRectangle( selRect
);
1605 // Don't clip exactly to the selection rectangle so we can draw
1606 // to the non-selected area in front of it.
1607 wxRect
clipRect(rect
.x
,rect
.y
,
1608 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1609 dc
.SetClippingRegion(clipRect
);
1612 // Save the library size a bit for platforms that re-implement this.
1613 void wxComboCtrlBase
::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1618 void wxComboCtrlBase
::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1620 int drawState
= m_btnState
;
1622 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1623 GetPopupWindowState() >= Animating
)
1624 drawState
|= wxCONTROL_PRESSED
;
1626 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1627 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1631 // Make sure area is not larger than the control
1632 if ( drawRect
.y
< rect
.y
)
1633 drawRect
.y
= rect
.y
;
1634 if ( drawRect
.height
> rect
.height
)
1635 drawRect
.height
= rect
.height
;
1637 bool enabled
= IsEnabled();
1640 drawState
|= wxCONTROL_DISABLED
;
1642 if ( !m_bmpNormal
.Ok() )
1644 if ( flags
& Button_BitmapOnly
)
1647 // Need to clear button background even if m_btn is present
1648 if ( flags
& Button_PaintBackground
)
1652 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1653 bgCol
= GetParent()->GetBackgroundColour();
1655 bgCol
= GetBackgroundColour();
1659 dc
.DrawRectangle(rect
);
1662 // Draw standard button
1663 wxRendererNative
::Get().DrawComboBoxDropButton(this,
1675 pBmp
= &m_bmpDisabled
;
1676 else if ( m_btnState
& wxCONTROL_PRESSED
)
1677 pBmp
= &m_bmpPressed
;
1678 else if ( m_btnState
& wxCONTROL_CURRENT
)
1681 pBmp
= &m_bmpNormal
;
1683 if ( m_blankButtonBg
)
1685 // If using blank button background, we need to clear its background
1686 // with button face colour instead of colour for rest of the control.
1687 if ( flags
& Button_PaintBackground
)
1689 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1690 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1693 dc
.DrawRectangle(rect
);
1696 if ( !(flags
& Button_BitmapOnly
) )
1698 wxRendererNative
::Get().DrawPushButton(this,
1707 // Need to clear button background even if m_btn is present
1708 // (assume non-button background was cleared just before this call so brushes are good)
1709 if ( flags
& Button_PaintBackground
)
1710 dc
.DrawRectangle(rect
);
1713 // Draw bitmap centered in drawRect
1714 dc
.DrawBitmap(*pBmp
,
1715 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1716 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1721 void wxComboCtrlBase
::RecalcAndRefresh()
1725 wxSizeEvent
evt(GetSize(),GetId());
1726 GetEventHandler()->ProcessEvent(evt
);
1731 // ----------------------------------------------------------------------------
1732 // miscellaneous event handlers
1733 // ----------------------------------------------------------------------------
1735 void wxComboCtrlBase
::OnTextCtrlEvent(wxCommandEvent
& event
)
1737 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1739 if ( m_ignoreEvtText
> 0 )
1746 // Change event id, object and string before relaying it forward
1747 event
.SetId(GetId());
1748 wxString s
= event
.GetString();
1749 event
.SetEventObject(this);
1754 // call if cursor is on button area or mouse is captured for the button
1755 bool wxComboCtrlBase
::HandleButtonMouseEvent( wxMouseEvent
& event
,
1758 int type
= event
.GetEventType();
1760 if ( type
== wxEVT_MOTION
)
1762 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1763 IsPopupWindowState(Hidden
) )
1765 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1767 // Mouse hover begins
1768 m_btnState
|= wxCONTROL_CURRENT
;
1769 if ( HasCapture() ) // Retain pressed state.
1770 m_btnState
|= wxCONTROL_PRESSED
;
1774 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1777 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1781 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1783 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1785 m_btnState
|= wxCONTROL_PRESSED
;
1788 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1791 // If showing popup now, do not capture mouse or there will be interference
1795 else if ( type
== wxEVT_LEFT_UP
)
1798 // Only accept event if mouse was left-press was previously accepted
1802 if ( m_btnState
& wxCONTROL_PRESSED
)
1804 // If mouse was inside, fire the click event.
1805 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1807 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1811 m_btnState
&= ~(wxCONTROL_PRESSED
);
1815 else if ( type
== wxEVT_LEAVE_WINDOW
)
1817 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1819 m_btnState
&= ~(wxCONTROL_CURRENT
);
1822 if ( IsPopupWindowState(Hidden
) )
1824 m_btnState
&= ~(wxCONTROL_PRESSED
);
1832 // Never have 'hot' state when popup is being shown
1833 // (this is mostly needed because of the animation).
1834 if ( !IsPopupWindowState(Hidden
) )
1835 m_btnState
&= ~wxCONTROL_CURRENT
;
1840 // returns true if event was consumed or filtered
1841 bool wxComboCtrlBase
::PreprocessMouseEvent( wxMouseEvent
& event
,
1842 int WXUNUSED(flags
) )
1844 wxLongLong t
= ::wxGetLocalTimeMillis();
1845 int evtType
= event
.GetEventType();
1847 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1848 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1850 if ( IsPopupWindowState(Visible
) &&
1851 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1859 // Filter out clicks on button immediately after popup dismiss
1860 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1862 event
.SetEventType(0);
1869 void wxComboCtrlBase
::HandleNormalMouseEvent( wxMouseEvent
& event
)
1871 int evtType
= event
.GetEventType();
1873 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1874 (m_windowStyle
& wxCB_READONLY
) )
1876 if ( GetPopupWindowState() >= Animating
)
1878 #if USES_WXPOPUPWINDOW
1879 // Click here always hides the popup.
1880 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1886 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1888 // In read-only mode, clicking the text is the
1889 // same as clicking the button.
1892 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1894 //if ( m_popupInterface->CycleValue() )
1896 if ( m_popupInterface
)
1897 m_popupInterface
->OnComboDoubleClick();
1901 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1903 if ( IsPopupShown() )
1905 // relay (some) mouse events to the popup
1906 m_popup
->GetEventHandler()->ProcessEvent(event
);
1908 else if ( event
.GetWheelAxis() == 0 &&
1909 event
.GetWheelRotation() != 0 &&
1910 event
.GetModifiers() == 0 )
1912 // Translate mousewheel actions into key up/down. This is
1913 // the simplest way of getting native behaviour: scrolling the
1914 // wheel moves selection up/down by one item.
1915 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1916 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1919 GetEventHandler()->ProcessEvent(kevent
);
1932 void wxComboCtrlBase
::OnKeyEvent(wxKeyEvent
& event
)
1934 if ( IsPopupShown() )
1936 // pass it to the popped up control
1937 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1941 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1943 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1945 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1949 if ( IsKeyPopupToggle(event
) )
1955 int comboStyle
= GetWindowStyle();
1956 wxComboPopup
* popupInterface
= GetPopupControl();
1958 if ( !popupInterface
)
1964 int keycode
= event
.GetKeyCode();
1966 if ( (comboStyle
& wxCB_READONLY
) ||
1967 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1969 popupInterface
->OnComboKeyEvent(event
);
1976 void wxComboCtrlBase
::OnCharEvent(wxKeyEvent
& event
)
1978 if ( IsPopupShown() )
1980 // pass it to the popped up control
1981 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1985 wxComboPopup
* popupInterface
= GetPopupControl();
1986 if ( popupInterface
)
1988 popupInterface
->OnComboCharEvent(event
);
1997 void wxComboCtrlBase
::OnFocusEvent( wxFocusEvent
& event
)
1999 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2001 wxWindow
* tc
= GetTextCtrl();
2002 if ( tc
&& tc
!= DoFindFocus() )
2011 void wxComboCtrlBase
::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2015 m_resetFocus
= false;
2016 wxWindow
* tc
= GetTextCtrl();
2022 void wxComboCtrlBase
::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2025 // left margin may also have changed
2026 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2027 m_marginLeft
= GetNativeTextIndent();
2031 // ----------------------------------------------------------------------------
2033 // ----------------------------------------------------------------------------
2035 // Create popup window and the child control
2036 void wxComboCtrlBase
::CreatePopup()
2038 wxComboPopup
* popupInterface
= m_popupInterface
;
2043 #ifdef wxComboPopupWindowBase2
2044 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2046 #if !USES_GENERICTLW
2047 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2049 int tlwFlags
= wxNO_BORDER
;
2050 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2051 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2054 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2055 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2056 wxPoint(-21,-21), wxSize(20, 20),
2059 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2060 wxPoint(-21,-21), wxSize(20, 20),
2064 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2067 #endif // wxComboPopupWindowBase2
2069 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2070 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2072 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2073 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2076 popupInterface
->Create(m_winPopup
);
2077 m_popup
= popup
= popupInterface
->GetControl();
2079 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2080 popup
->PushEventHandler( m_popupEvtHandler
);
2082 // This may be helpful on some platforms
2083 // (eg. it bypasses a wxGTK popupwindow bug where
2084 // window is not initially hidden when it should be)
2087 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2090 // Destroy popup window and the child control
2091 void wxComboCtrlBase
::DestroyPopup()
2096 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2098 wxDELETE(m_popupEvtHandler
);
2100 wxDELETE(m_popupInterface
);
2104 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2105 wxDELETE(m_popupWinEvtHandler
);
2106 m_winPopup
->Destroy();
2113 void wxComboCtrlBase
::DoSetPopupControl(wxComboPopup
* iface
)
2115 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2119 iface
->InitBase(this);
2122 m_popupInterface
= iface
;
2124 if ( !iface
->LazyCreate() )
2133 // This must be done after creation
2134 if ( m_valueString
.length() )
2136 iface
->SetStringValue(m_valueString
);
2141 // Ensures there is atleast the default popup
2142 void wxComboCtrlBase
::EnsurePopupControl()
2144 if ( !m_popupInterface
)
2145 SetPopupControl(NULL
);
2148 void wxComboCtrlBase
::OnButtonClick()
2150 // Derived classes can override this method for totally custom
2152 switch ( GetPopupWindowState() )
2169 void wxComboCtrlBase
::Popup()
2171 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2172 event
.SetEventObject(this);
2173 HandleWindowEvent(event
);
2178 void wxComboCtrlBase
::ShowPopup()
2180 EnsurePopupControl();
2181 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2183 if ( IsPopupWindowState(Animating
) )
2188 // Space above and below
2194 wxSize ctrlSz
= GetSize();
2196 screenHeight
= wxSystemSettings
::GetMetric( wxSYS_SCREEN_Y
);
2197 scrPos
= GetParent()->ClientToScreen(GetPosition());
2199 spaceAbove
= scrPos
.y
;
2200 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2202 maxHeightPopup
= spaceBelow
;
2203 if ( spaceAbove
> spaceBelow
)
2204 maxHeightPopup
= spaceAbove
;
2207 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2209 if ( widthPopup
< m_widthMinPopup
)
2210 widthPopup
= m_widthMinPopup
;
2212 wxWindow
* winPopup
= m_winPopup
;
2215 // Need to disable tab traversal of parent
2217 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2218 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2219 // that if transient popup is open, then tab traversal is to be ignored.
2220 // However, I think this code would still be needed for cases where
2221 // transient popup doesn't work yet (wxWinCE?).
2222 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2223 wxWindow
* parent
= mainCtrl
->GetParent();
2224 int parentFlags
= parent
->GetWindowStyle();
2225 if ( parentFlags
& wxTAB_TRAVERSAL
)
2227 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2228 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2234 winPopup
= m_winPopup
;
2244 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2246 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2247 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2250 popup
->SetSize(adjustedSize
);
2252 m_popupInterface
->OnPopup();
2255 // Reposition and resize popup window
2258 wxSize szp
= popup
->GetSize();
2261 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2263 // Default anchor is wxLEFT
2264 int anchorSide
= m_anchorSide
;
2266 anchorSide
= wxLEFT
;
2268 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2269 int leftX
= scrPos
.x
- m_extLeft
;
2271 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2274 int screenWidth
= wxSystemSettings
::GetMetric( wxSYS_SCREEN_X
);
2276 // If there is not enough horizontal space, anchor on the other side.
2277 // If there is no space even then, place the popup at x 0.
2278 if ( anchorSide
== wxRIGHT
)
2282 if ( (leftX
+szp
.x
) < screenWidth
)
2283 anchorSide
= wxLEFT
;
2290 if ( (leftX
+szp
.x
) >= screenWidth
)
2293 anchorSide
= wxRIGHT
;
2299 // Select x coordinate according to the anchor side
2300 if ( anchorSide
== wxRIGHT
)
2302 else if ( anchorSide
== wxLEFT
)
2307 int showFlags
= CanDeferShow
;
2309 if ( spaceBelow
< szp
.y
)
2311 popupY
= scrPos
.y
- szp
.y
;
2312 showFlags
|= ShowAbove
;
2315 #if INSTALL_TOPLEV_HANDLER
2316 // Put top level window event handler into place
2317 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2319 if ( !m_toplevEvtHandler
)
2320 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2322 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2324 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2325 toplev
->PushEventHandler( m_toplevEvtHandler
);
2329 // Set string selection (must be this way instead of SetStringSelection)
2332 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2333 m_text
->SelectAll();
2335 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2339 // This is neede since focus/selection indication may change when popup is shown
2343 // This must be after SetStringValue
2344 m_popupWinState
= Animating
;
2346 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2349 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2350 AnimateShow( popupWinRect
, showFlags
) )
2352 DoShowPopup( popupWinRect
, showFlags
);
2356 bool wxComboCtrlBase
::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2361 void wxComboCtrlBase
::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2363 wxWindow
* winPopup
= m_winPopup
;
2365 if ( IsPopupWindowState(Animating
) )
2367 // Make sure the popup window is shown in the right position.
2368 // Should not matter even if animation already did this.
2370 // Some platforms (GTK) may like SetSize and Move to be separate
2371 // (though the bug was probably fixed).
2372 winPopup
->SetSize( rect
);
2374 #if USES_WXPOPUPTRANSIENTWINDOW
2375 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2376 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2381 m_popupWinState
= Visible
;
2383 // If popup window was a generic top-level window, or the
2384 // wxPopupWindow implemenation on this platform is classified as
2385 // perfect, then we should be able to safely set focus to the popup
2387 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2388 m_popup
->SetFocus();
2390 else if ( IsPopupWindowState(Hidden
) )
2392 // Animation was aborted
2394 wxASSERT( !winPopup
->IsShown() );
2396 m_popupWinState
= Hidden
;
2402 void wxComboCtrlBase
::OnPopupDismiss(bool generateEvent
)
2404 // Just in case, avoid double dismiss
2405 if ( IsPopupWindowState(Hidden
) )
2408 // This must be set before focus - otherwise there will be recursive
2409 // OnPopupDismisses.
2410 m_popupWinState
= Hidden
;
2413 m_winPopup
->Disable();
2415 // Inform popup control itself
2416 m_popupInterface
->OnDismiss();
2418 if ( m_popupEvtHandler
)
2419 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2421 #if INSTALL_TOPLEV_HANDLER
2422 // Remove top level window event handler
2423 if ( m_toplevEvtHandler
)
2425 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2427 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2431 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2433 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2434 m_timeCanAcceptClick
+= 150;
2436 // If cursor not on dropdown button, then clear its state
2437 // (technically not required by all ports, but do it for all just in case)
2438 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2441 // Return parent's tab traversal flag.
2442 // See ShowPopup for notes.
2443 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2445 wxWindow
* parent
= GetParent();
2446 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2447 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2450 // refresh control (necessary even if m_text)
2455 if ( generateEvent
)
2457 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2458 event
.SetEventObject(this);
2459 HandleWindowEvent(event
);
2463 void wxComboCtrlBase
::HidePopup(bool generateEvent
)
2465 // Should be able to call this without popup interface
2466 if ( IsPopupWindowState(Hidden
) )
2469 // transfer value and show it in textctrl, if any
2470 if ( !IsPopupWindowState(Animating
) )
2471 SetValueByUser( m_popupInterface
->GetStringValue() );
2475 OnPopupDismiss(generateEvent
);
2478 // ----------------------------------------------------------------------------
2479 // customization methods
2480 // ----------------------------------------------------------------------------
2482 void wxComboCtrlBase
::SetButtonPosition( int width
, int height
,
2483 int side
, int spacingX
)
2488 m_btnSpacingX
= spacingX
;
2490 if ( width
> 0 || height
> 0 || spacingX
)
2491 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2496 wxSize wxComboCtrlBase
::GetButtonSize()
2498 if ( m_btnSize
.x
> 0 )
2501 wxSize
retSize(m_btnWid
,m_btnHei
);
2503 // Need to call CalculateAreas now if button size is
2504 // is not explicitly specified.
2505 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2509 retSize
= m_btnSize
;
2515 void wxComboCtrlBase
::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2517 const wxBitmap
& bmpPressed
,
2518 const wxBitmap
& bmpHover
,
2519 const wxBitmap
& bmpDisabled
)
2521 m_bmpNormal
= bmpNormal
;
2522 m_blankButtonBg
= blankButtonBg
;
2524 if ( bmpPressed
.Ok() )
2525 m_bmpPressed
= bmpPressed
;
2527 m_bmpPressed
= bmpNormal
;
2529 if ( bmpHover
.Ok() )
2530 m_bmpHover
= bmpHover
;
2532 m_bmpHover
= bmpNormal
;
2534 if ( bmpDisabled
.Ok() )
2535 m_bmpDisabled
= bmpDisabled
;
2537 m_bmpDisabled
= bmpNormal
;
2542 void wxComboCtrlBase
::SetCustomPaintWidth( int width
)
2546 // move textctrl accordingly
2547 wxRect r
= m_text
->GetRect();
2548 int inc
= width
- m_widthCustomPaint
;
2551 m_text
->SetSize( r
);
2554 m_widthCustomPaint
= width
;
2559 bool wxComboCtrlBase
::DoSetMargins(const wxPoint
& margins
)
2561 // For general sanity's sake, we ignore top margin. Instead
2562 // we will always try to center the text vertically.
2565 if ( margins
.x
!= -1 )
2567 m_marginLeft
= margins
.x
;
2568 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2572 m_marginLeft
= GetNativeTextIndent();
2573 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2576 if ( margins
.y
!= -1 )
2586 wxPoint wxComboCtrlBase
::DoGetMargins() const
2588 return wxPoint(m_marginLeft
, -1);
2591 #if WXWIN_COMPATIBILITY_2_8
2592 void wxComboCtrlBase
::SetTextIndent( int indent
)
2596 m_marginLeft
= GetNativeTextIndent();
2597 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2601 m_marginLeft
= indent
;
2602 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2608 wxCoord wxComboCtrlBase
::GetTextIndent() const
2610 return m_marginLeft
;
2614 wxCoord wxComboCtrlBase
::GetNativeTextIndent() const
2616 return DEFAULT_TEXT_INDENT
;
2619 void wxComboCtrlBase
::SetTextCtrlStyle( int style
)
2621 m_textCtrlStyle
= style
;
2624 m_text
->SetWindowStyle(style
);
2627 // ----------------------------------------------------------------------------
2628 // wxTextEntry interface
2629 // ----------------------------------------------------------------------------
2631 wxString wxComboCtrlBase
::DoGetValue() const
2634 return m_text
->GetValue();
2635 return m_valueString
;
2638 void wxComboCtrlBase
::SetValueWithEvent(const wxString
& value
,
2641 DoSetValue(value
, withEvent ? SetValue_SendEvent
: 0);
2644 void wxComboCtrlBase
::OnSetValue(const wxString
& value
)
2646 // Note: before wxComboCtrl inherited from wxTextEntry,
2647 // this code used to be in SetValueWithEvent().
2649 // Since wxComboPopup may want to paint the combo as well, we need
2650 // to set the string value here (as well as sometimes in ShowPopup).
2651 if ( m_valueString
!= value
)
2654 wxString trueValue
= value
;
2656 // Conform to wxComboBox behavior: read-only control can only accept
2657 // valid list items and empty string
2658 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2660 found
= m_popupInterface
->FindItem(value
,
2666 m_valueString
= trueValue
;
2668 EnsurePopupControl();
2670 if ( m_popupInterface
)
2671 m_popupInterface
->SetStringValue(trueValue
);
2678 void wxComboCtrlBase
::SetValueByUser(const wxString
& value
)
2680 // NB: Order of function calls is important here. Otherwise
2681 // the SelectAll() may not work.
2685 m_text
->SetValue(value
);
2687 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2688 m_text
->SelectAll();
2694 // In this SetValue variant wxComboPopup::SetStringValue is not called
2695 void wxComboCtrlBase
::SetText(const wxString
& value
)
2697 // Unlike in SetValue(), this must be called here or
2698 // the behaviour will no be consistent in readonlys.
2699 EnsurePopupControl();
2701 m_valueString
= value
;
2706 m_text
->SetValue( value
);
2712 void wxComboCtrlBase
::Copy()
2718 void wxComboCtrlBase
::Cut()
2724 void wxComboCtrlBase
::Paste()
2730 void wxComboCtrlBase
::SetInsertionPoint(long pos
)
2733 m_text
->SetInsertionPoint(pos
);
2736 long wxComboCtrlBase
::GetInsertionPoint() const
2739 return m_text
->GetInsertionPoint();
2744 long wxComboCtrlBase
::GetLastPosition() const
2747 return m_text
->GetLastPosition();
2752 void wxComboCtrlBase
::WriteText(const wxString
& text
)
2756 m_text
->WriteText(text
);
2757 OnSetValue(m_text
->GetValue());
2765 void wxComboCtrlBase
::DoSetValue(const wxString
& value
, int flags
)
2769 if ( flags
& SetValue_SendEvent
)
2770 m_text
->SetValue(value
);
2772 m_text
->ChangeValue(value
);
2778 void wxComboCtrlBase
::Replace(long from
, long to
, const wxString
& value
)
2782 m_text
->Replace(from
, to
, value
);
2783 OnSetValue(m_text
->GetValue());
2787 void wxComboCtrlBase
::Remove(long from
, long to
)
2791 m_text
->Remove(from
, to
);
2792 OnSetValue(m_text
->GetValue());
2796 void wxComboCtrlBase
::SetSelection(long from
, long to
)
2799 m_text
->SetSelection(from
, to
);
2802 void wxComboCtrlBase
::GetSelection(long *from
, long *to
) const
2806 m_text
->GetSelection(from
, to
);
2815 bool wxComboCtrlBase
::IsEditable() const
2818 return m_text
->IsEditable();
2822 void wxComboCtrlBase
::SetEditable(bool editable
)
2825 m_text
->SetEditable(editable
);
2828 void wxComboCtrlBase
::Undo()
2834 void wxComboCtrlBase
::Redo()
2840 bool wxComboCtrlBase
::CanUndo() const
2843 return m_text
->CanUndo();
2848 bool wxComboCtrlBase
::CanRedo() const
2851 return m_text
->CanRedo();
2856 bool wxComboCtrlBase
::SetHint(const wxString
& hint
)
2861 res
= m_text
->SetHint(hint
);
2866 wxString wxComboCtrlBase
::GetHint() const
2871 #endif // wxUSE_COMBOCTRL