1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
27 #include "wx/combobox.h"
28 extern WXDLLEXPORT_DATA(const char) wxComboBoxNameStr
[] = "comboBox";
36 #include "wx/dcclient.h"
37 #include "wx/settings.h"
39 #include "wx/textctrl.h"
42 #include "wx/tooltip.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 wxDEFINE_FLAGS( wxComboBoxStyle
)
52 wxBEGIN_FLAGS( wxComboBoxStyle
)
53 // new style border flags, we put them first to
54 // use them for streaming out
55 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
56 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
57 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
58 wxFLAGS_MEMBER(wxBORDER_RAISED
)
59 wxFLAGS_MEMBER(wxBORDER_STATIC
)
60 wxFLAGS_MEMBER(wxBORDER_NONE
)
62 // old style border flags
63 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
64 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
65 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
66 wxFLAGS_MEMBER(wxRAISED_BORDER
)
67 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
68 wxFLAGS_MEMBER(wxBORDER
)
70 // standard window styles
71 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
72 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
73 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
74 wxFLAGS_MEMBER(wxWANTS_CHARS
)
75 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
76 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
77 wxFLAGS_MEMBER(wxVSCROLL
)
78 wxFLAGS_MEMBER(wxHSCROLL
)
80 wxFLAGS_MEMBER(wxCB_SIMPLE
)
81 wxFLAGS_MEMBER(wxCB_SORT
)
82 wxFLAGS_MEMBER(wxCB_READONLY
)
83 wxFLAGS_MEMBER(wxCB_DROPDOWN
)
85 wxEND_FLAGS( wxComboBoxStyle
)
87 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxControl
, "wx/combobox.h")
89 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
90 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
)
91 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
94 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
95 0 /*flags*/, wxT("Helpstring"), wxT("group"))
96 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
97 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
98 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
99 0 /*flags*/, wxT("Helpstring"), wxT("group"))
100 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
101 0 /*flags*/, wxT("Helpstring"), wxT("group"))
103 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
104 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
105 wxT("Helpstring"), wxT("group")) // style
106 wxEND_PROPERTIES_TABLE()
108 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
110 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
111 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
114 // ----------------------------------------------------------------------------
116 #define DEFAULT_DROPBUTTON_WIDTH 19
118 #define BMP_BUTTON_MARGIN 4
120 #define DEFAULT_POPUP_HEIGHT 400
122 #define DEFAULT_TEXT_INDENT 3
124 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
127 #if defined(__WXMSW__)
129 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
130 #include "wx/frame.h"
131 #define wxCC_GENERIC_TLW_IS_FRAME
132 #define wxComboCtrlGenericTLW wxFrame
134 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
135 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
136 // native controls work on it like normal.
137 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
138 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
139 #define FOCUS_RING 0 // No focus ring on wxMSW
141 //#undef wxUSE_POPUPWIN
142 //#define wxUSE_POPUPWIN 0
144 #elif defined(__WXGTK__)
146 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
147 // this bug: If wxDialog is hidden, its position becomes corrupt
148 // between hide and next show, but without internal coordinates being
149 // reflected (or something like that - atleast commenting out ->Hide()
150 // seemed to eliminate the position change).
152 #include "wx/dialog.h"
153 #define wxCC_GENERIC_TLW_IS_DIALOG
154 #define wxComboCtrlGenericTLW wxDialog
156 #if defined(__WXGTK20__)
157 # include "wx/gtk/private.h"
159 # include "wx/gtk1/private.h"
162 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
163 // 'perfect' popup, as it can successfully host child controls even in
164 // popups that are shown in modal dialogs.
166 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
167 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
168 // native controls work on it like normal.
169 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
170 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
171 #define FOCUS_RING 0 // No focus ring on wxGTK
173 #elif defined(__WXMAC__)
175 #include "wx/nonownedwnd.h"
176 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
177 #define wxComboCtrlGenericTLW wxNonOwnedWindow
179 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
180 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
181 // native controls work on it like normal.
182 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
183 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
184 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
186 #undef DEFAULT_DROPBUTTON_WIDTH
187 #define DEFAULT_DROPBUTTON_WIDTH 22
189 #define COMBO_MARGIN FOCUS_RING
193 #include "wx/dialog.h"
194 #define wxCC_GENERIC_TLW_IS_DIALOG
195 #define wxComboCtrlGenericTLW wxDialog
197 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
198 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
199 // native controls work on it like normal.
200 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
201 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
207 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
208 // what the wxUSE_POPUPWIN says.
209 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
210 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
211 #undef wxUSE_POPUPWIN
212 #define wxUSE_POPUPWIN 0
217 #include "wx/popupwin.h"
219 #undef USE_TRANSIENT_POPUP
220 #define USE_TRANSIENT_POPUP 0
224 // Define different types of popup windows
228 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
229 POPUPWIN_WXPOPUPWINDOW
= 2,
230 POPUPWIN_GENERICTLW
= 3
234 #if USE_TRANSIENT_POPUP
235 // wxPopupTransientWindow is implemented
237 #define wxComboPopupWindowBase wxPopupTransientWindow
238 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
239 #define USES_WXPOPUPTRANSIENTWINDOW 1
241 #if TRANSIENT_POPUPWIN_IS_PERFECT
243 #elif POPUPWIN_IS_PERFECT
244 #define wxComboPopupWindowBase2 wxPopupWindow
245 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
246 #define USES_WXPOPUPWINDOW 1
248 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
249 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
250 #define USES_GENERICTLW 1
254 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
256 #define wxComboPopupWindowBase wxPopupWindow
257 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
258 #define USES_WXPOPUPWINDOW 1
260 #if !POPUPWIN_IS_PERFECT
261 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
262 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
263 #define USES_GENERICTLW 1
267 // wxPopupWindow is not implemented
269 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
270 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
271 #define USES_GENERICTLW 1
276 #ifndef USES_WXPOPUPTRANSIENTWINDOW
277 #define USES_WXPOPUPTRANSIENTWINDOW 0
280 #ifndef USES_WXPOPUPWINDOW
281 #define USES_WXPOPUPWINDOW 0
284 #ifndef USES_GENERICTLW
285 #define USES_GENERICTLW 0
289 #if USES_WXPOPUPWINDOW
290 #define INSTALL_TOPLEV_HANDLER 1
292 #define INSTALL_TOPLEV_HANDLER 0
296 // Returns true if given popup window type can be classified as perfect
298 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
300 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
301 wxUnusedVar(popupWinType
);
304 return ( popupWinType
== POPUPWIN_GENERICTLW
305 #if POPUPWIN_IS_PERFECT
306 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
308 #if TRANSIENT_POPUPWIN_IS_PERFECT
309 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
318 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
322 // ----------------------------------------------------------------------------
323 // wxComboFrameEventHandler takes care of hiding the popup when events happen
324 // in its top level parent.
325 // ----------------------------------------------------------------------------
327 #if INSTALL_TOPLEV_HANDLER
330 // This will no longer be necessary after wxTransientPopupWindow
331 // works well on all platforms.
334 class wxComboFrameEventHandler
: public wxEvtHandler
337 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
338 virtual ~wxComboFrameEventHandler();
342 void OnIdle( wxIdleEvent
& event
);
343 void OnMouseEvent( wxMouseEvent
& event
);
344 void OnActivate( wxActivateEvent
& event
);
345 void OnResize( wxSizeEvent
& event
);
346 void OnMove( wxMoveEvent
& event
);
347 void OnMenuEvent( wxMenuEvent
& event
);
348 void OnClose( wxCloseEvent
& event
);
351 wxWindow
* m_focusStart
;
352 wxComboCtrlBase
* m_combo
;
355 DECLARE_EVENT_TABLE()
358 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
359 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
360 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
361 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
362 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
363 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
364 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
365 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
366 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
367 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
370 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
376 wxComboFrameEventHandler::~wxComboFrameEventHandler()
380 void wxComboFrameEventHandler::OnPopup()
382 m_focusStart
= ::wxWindow::FindFocus();
385 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
387 wxWindow
* winFocused
= ::wxWindow::FindFocus();
389 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
390 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
393 winFocused
!= m_focusStart
&&
394 winFocused
!= popup
&&
395 winFocused
->GetParent() != popup
&&
396 winFocused
!= winpopup
&&
397 winFocused
->GetParent() != winpopup
&&
398 winFocused
!= m_combo
&&
399 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
402 m_combo
->HidePopup(true);
408 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
410 m_combo
->HidePopup(true);
414 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
416 m_combo
->HidePopup(true);
420 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
422 m_combo
->HidePopup(true);
426 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
428 m_combo
->HidePopup(true);
432 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
434 m_combo
->HidePopup(true);
438 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
440 m_combo
->HidePopup(true);
444 #endif // INSTALL_TOPLEV_HANDLER
446 // ----------------------------------------------------------------------------
447 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
449 // ----------------------------------------------------------------------------
451 class wxComboPopupWindow
: public wxComboPopupWindowBase
455 wxComboPopupWindow( wxComboCtrlBase
*parent
,
457 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
458 : wxComboPopupWindowBase(parent
,style
)
460 : wxComboPopupWindowBase(parent
,
471 #if USES_WXPOPUPTRANSIENTWINDOW
472 virtual bool Show( bool show
);
473 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
475 virtual void OnDismiss();
483 #if USES_WXPOPUPTRANSIENTWINDOW
484 bool wxComboPopupWindow::Show( bool show
)
486 // Guard against recursion
488 return wxComboPopupWindowBase::Show(show
);
492 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
494 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
496 if ( show
!= ptw
->IsShown() )
499 // We used to do wxPopupTransientWindow::Popup here,
500 // but this would hide normal Show, which we are
501 // also going to need.
512 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
514 return wxPopupTransientWindow::ProcessLeftDown(event
);
517 // First thing that happens when a transient popup closes is that this method gets called.
518 void wxComboPopupWindow::OnDismiss()
520 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
521 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
522 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
524 combo
->OnPopupDismiss(true);
526 #endif // USES_WXPOPUPTRANSIENTWINDOW
529 // ----------------------------------------------------------------------------
530 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
531 // of a popup window. It is separate so we can have different types
533 // ----------------------------------------------------------------------------
535 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
539 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
544 void OnSizeEvent( wxSizeEvent
& event
);
545 void OnKeyEvent(wxKeyEvent
& event
);
547 void OnActivate( wxActivateEvent
& event
);
551 wxComboCtrlBase
* m_combo
;
553 DECLARE_EVENT_TABLE()
557 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
558 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
559 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
560 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
562 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
564 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
568 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
570 // Block the event so that the popup control does not get auto-resized.
573 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
575 // Relay keyboard event to the main child controls
576 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
577 wxWindowList::iterator node
= children
.begin();
578 wxWindow
* child
= (wxWindow
*)*node
;
579 child
->GetEventHandler()->ProcessEvent(event
);
583 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
585 if ( !event
.GetActive() )
587 // Tell combo control that we are dismissed.
588 m_combo
->HidePopup(true);
596 // ----------------------------------------------------------------------------
599 // ----------------------------------------------------------------------------
601 wxComboPopup::~wxComboPopup()
605 void wxComboPopup::OnPopup()
609 void wxComboPopup::OnDismiss()
613 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
615 return wxStaticCast(m_combo
, wxComboCtrl
);
618 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
620 int WXUNUSED(maxHeight
) )
622 return wxSize(minWidth
,prefHeight
);
625 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
626 wxDC
& dc
, const wxRect
& rect
)
628 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
630 combo
->PrepareBackground(dc
,rect
,0);
632 dc
.DrawText( combo
->GetValue(),
633 rect
.x
+ combo
->m_marginLeft
,
634 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
638 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
640 DefaultPaintComboControl(m_combo
,dc
,rect
);
643 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
648 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
653 void wxComboPopup::OnComboDoubleClick()
657 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
661 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
662 wxString
* WXUNUSED(trueItem
))
667 bool wxComboPopup::LazyCreate()
672 void wxComboPopup::Dismiss()
674 m_combo
->HidePopup(true);
677 void wxComboPopup::DestroyPopup()
679 // Here we make sure that the popup control's Destroy() gets called.
680 // This is necessary for the wxPersistentWindow to work properly.
681 wxWindow
* popupCtrl
= GetControl();
684 // While all wxComboCtrl examples have m_popupInterface and
685 // popupCtrl as the same class (that will be deleted via the
686 // Destroy() call below), it is technically still possible to
687 // have implementations where they are in fact not same
688 // multiple-inherited class. Here we use C++ RTTI to check for
691 // It is probably better to delete m_popupInterface first, so
692 // that it retains access to its popup control window.
693 if ( dynamic_cast<void*>(this) !=
694 dynamic_cast<void*>(popupCtrl
) )
697 popupCtrl
->Destroy();
705 // ----------------------------------------------------------------------------
707 // ----------------------------------------------------------------------------
710 // This is pushed to the event handler queue of the child textctrl.
712 class wxComboBoxExtraInputHandler
: public wxEvtHandler
716 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
721 virtual ~wxComboBoxExtraInputHandler() { }
722 void OnKey(wxKeyEvent
& event
);
723 void OnFocus(wxFocusEvent
& event
);
726 wxComboCtrlBase
* m_combo
;
729 DECLARE_EVENT_TABLE()
733 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
734 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
735 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
736 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
737 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
738 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
742 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
744 // Let the wxComboCtrl event handler have a go first.
745 wxComboCtrlBase
* combo
= m_combo
;
747 wxKeyEvent
redirectedEvent(event
);
748 redirectedEvent
.SetId(combo
->GetId());
749 redirectedEvent
.SetEventObject(combo
);
751 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
753 // Don't let TAB through to the text ctrl - looks ugly
754 if ( event
.GetKeyCode() != WXK_TAB
)
759 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
761 // FIXME: This code does run when control is clicked,
762 // yet on Windows it doesn't select all the text.
763 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
764 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
766 if ( m_combo
->GetTextCtrl() )
767 m_combo
->GetTextCtrl()->SelectAll();
769 m_combo
->SetSelection(-1,-1);
772 // Send focus indication to parent.
773 // NB: This is needed for cases where the textctrl gets focus
774 // instead of its parent. While this may trigger multiple
775 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
776 // from combo's focus event handler), they should be quite
778 wxFocusEvent
evt2(event
);
779 evt2
.SetId(m_combo
->GetId());
780 evt2
.SetEventObject(m_combo
);
781 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
788 // This is pushed to the event handler queue of the control in popup.
791 class wxComboPopupEvtHandler
: public wxEvtHandler
795 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
799 m_beenInside
= false;
801 // Let's make it so that the popup control will not receive mouse
802 // events until mouse left button has been up.
803 m_blockEventsToPopup
= true;
805 virtual ~wxComboPopupEvtHandler() { }
807 void OnMouseEvent( wxMouseEvent
& event
);
809 // Called from wxComboCtrlBase::OnPopupDismiss
810 void OnPopupDismiss()
812 m_beenInside
= false;
813 m_blockEventsToPopup
= true;
817 wxComboCtrlBase
* m_combo
;
820 bool m_blockEventsToPopup
;
823 DECLARE_EVENT_TABLE()
827 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
828 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
832 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
834 wxPoint pt
= event
.GetPosition();
835 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
836 int evtType
= event
.GetEventType();
837 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
838 bool relayToButton
= false;
842 if ( !isInside
|| !m_combo
->IsPopupShown() )
844 // Mouse is outside the popup or popup is not actually shown (yet)
846 if ( evtType
== wxEVT_MOTION
||
847 evtType
== wxEVT_LEFT_DOWN
||
848 evtType
== wxEVT_LEFT_UP
||
849 evtType
== wxEVT_RIGHT_DOWN
)
851 // Block motion and click events outside the popup
857 // Mouse is inside the popup, which is fully shown
861 // Do not let the popup control respond to mouse events until
862 // mouse press used to display the popup has been lifted. This
863 // is important for users with slower mouse fingers or mouse
864 // drivers. Note that we have some redundancy here, just in
865 // case the popup is some native control that does not emit all
866 // mouse event types.
867 if ( evtType
== wxEVT_MOTION
)
869 if ( m_blockEventsToPopup
)
871 if ( event
.LeftIsDown() )
874 m_blockEventsToPopup
= false;
877 else if ( evtType
== wxEVT_LEFT_DOWN
)
879 if ( m_blockEventsToPopup
)
880 m_blockEventsToPopup
= false;
882 else if ( evtType
== wxEVT_LEFT_UP
)
884 if ( m_blockEventsToPopup
)
886 // On first left up, stop blocking mouse events (but still
888 m_blockEventsToPopup
= false;
891 // Also, this button press was (probably) used to display
892 // the popup, so relay it back to the drop-down button
893 // (which supposedly originated it). This is necessary to
894 // refresh it properly.
895 relayToButton
= true;
898 else if ( m_blockEventsToPopup
)
905 // Some mouse events to popup that happen outside it, before cursor
906 // has been inside the popup, need to be ignored by it but relayed to
909 if ( evtType
== wxEVT_LEFT_UP
)
911 if ( !m_combo
->IsPopupShown() )
914 relayToButton
= true;
916 else if ( !isInside
&& !m_beenInside
)
918 // Popup is shown but the cursor is not inside, nor it has been
919 relayToButton
= true;
925 wxWindow
* btn
= m_combo
->GetButton();
927 btn
->GetEventHandler()->ProcessEvent(event
);
929 // Bypass the event handling mechanism. Using it would be
930 // confusing for the platform-specific wxComboCtrl
932 m_combo
->HandleButtonMouseEvent(event
, 0);
936 // ----------------------------------------------------------------------------
937 // wxComboCtrlTextCtrl
938 // ----------------------------------------------------------------------------
940 class wxComboCtrlTextCtrl
: public wxTextCtrl
943 wxComboCtrlTextCtrl() : wxTextCtrl() { }
944 virtual ~wxComboCtrlTextCtrl() { }
946 virtual wxWindow
*GetMainWindowOfCompositeControl()
948 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
950 // Returning this instead of just 'parent' lets FindFocus work
951 // correctly even when parent control is a child of a composite
952 // generic control (as is case with wxGenericDatePickerCtrl).
953 return combo
->GetMainWindowOfCompositeControl();
957 // ----------------------------------------------------------------------------
959 // ----------------------------------------------------------------------------
962 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
963 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
964 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
965 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
966 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
967 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
968 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
969 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
970 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
971 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
972 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
976 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
978 void wxComboCtrlBase::Init()
982 m_popupWinState
= Hidden
;
985 m_popupInterface
= NULL
;
987 m_popupEvtHandler
= NULL
;
988 m_textEvtHandler
= NULL
;
990 #if INSTALL_TOPLEV_HANDLER
991 m_toplevEvtHandler
= NULL
;
994 m_mainCtrlWnd
= this;
997 m_widthMinPopup
= -1;
999 m_widthCustomPaint
= 0;
1000 m_widthCustomBorder
= 0;
1003 m_btnWidDefault
= 0;
1004 m_blankButtonBg
= false;
1005 m_ignoreEvtText
= 0;
1006 m_popupWinType
= POPUPWIN_NONE
;
1007 m_btnWid
= m_btnHei
= -1;
1008 m_btnSide
= wxRIGHT
;
1015 m_textCtrlStyle
= 0;
1016 m_timeCanAcceptClick
= 0;
1018 m_resetFocus
= false;
1019 m_hasTcBgCol
= false;
1022 bool wxComboCtrlBase::Create(wxWindow
*parent
,
1024 const wxString
& value
,
1028 const wxValidator
& validator
,
1029 const wxString
& name
)
1031 if ( !wxControl::Create(parent
,
1035 style
| wxWANTS_CHARS
,
1040 m_valueString
= value
;
1044 m_marginLeft
= GetNativeTextIndent();
1046 m_iFlags
|= wxCC_IFLAG_CREATED
;
1048 // If x and y indicate valid size, wxSizeEvent won't be
1049 // emitted automatically, so we need to add artifical one.
1050 if ( size
.x
> 0 && size
.y
> 0 )
1052 wxSizeEvent
evt(size
,GetId());
1053 GetEventHandler()->AddPendingEvent(evt
);
1059 void wxComboCtrlBase::InstallInputHandlers()
1063 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1064 m_text
->PushEventHandler(m_textEvtHandler
);
1069 wxComboCtrlBase::CreateTextCtrl(int style
)
1071 if ( !(m_windowStyle
& wxCB_READONLY
) )
1076 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1077 // not used by the wxPropertyGrid and therefore the tab is processed by
1078 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1079 // navigation event is then sent to the wrong window.
1080 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1082 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1083 style
|= wxTE_PROCESS_ENTER
;
1085 // Ignore EVT_TEXT generated by the constructor (but only
1086 // if the event redirector already exists)
1087 // NB: This must be " = 1" instead of "++";
1088 if ( m_textEvtHandler
)
1089 m_ignoreEvtText
= 1;
1091 m_ignoreEvtText
= 0;
1093 m_text
= new wxComboCtrlTextCtrl();
1094 m_text
->Create(this, wxID_ANY
, m_valueString
,
1095 wxDefaultPosition
, wxSize(10,-1),
1097 m_text
->SetHint(m_hintText
);
1101 void wxComboCtrlBase::OnThemeChange()
1103 // Because wxComboCtrl has transparent parts on most platforms, we
1104 // don't want to touch the actual background colour. Instead, we just
1105 // usually re-obtain m_tcBgCol here.
1107 #if defined(__WXMSW__) || defined(__WXGTK__)
1108 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1110 wxVisualAttributes vattrs
;
1111 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1112 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1115 if ( !m_hasTcBgCol
)
1116 m_tcBgCol
= vattrs
.colBg
;
1119 // Only change the colours if application has not specified
1123 SetOwnForegroundColour(vattrs
.colFg
);
1125 if ( !HasTransparentBackground() )
1127 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1129 #endif // !__WXMAC__
1132 wxComboCtrlBase::~wxComboCtrlBase()
1137 #if INSTALL_TOPLEV_HANDLER
1138 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1139 m_toplevEvtHandler
= NULL
;
1145 m_text
->RemoveEventHandler(m_textEvtHandler
);
1147 delete m_textEvtHandler
;
1151 // ----------------------------------------------------------------------------
1153 // ----------------------------------------------------------------------------
1155 // Recalculates button and textctrl areas
1156 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1158 wxSize sz
= GetClientSize();
1159 int customBorder
= m_widthCustomBorder
;
1160 int btnBorder
; // border for button only
1162 // check if button should really be outside the border: we'll do it it if
1163 // its platform default or bitmap+pushbutton background is used, but not if
1164 // there is vertical size adjustment or horizontal spacing.
1165 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1166 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
1167 m_btnSpacingX
== 0 &&
1170 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1173 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1174 m_btnSpacingX
== 0 && !m_bmpNormal
.Ok() )
1176 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1181 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1182 btnBorder
= customBorder
;
1185 // Defaul indentation
1186 if ( m_marginLeft
< 0 )
1187 m_marginLeft
= GetNativeTextIndent();
1189 int butWidth
= btnWidth
;
1191 if ( butWidth
<= 0 )
1192 butWidth
= m_btnWidDefault
;
1194 m_btnWidDefault
= butWidth
;
1196 if ( butWidth
<= 0 )
1199 int butHeight
= sz
.y
- btnBorder
*2;
1201 // Adjust button width
1203 butWidth
= m_btnWid
;
1206 // Adjust button width to match aspect ratio
1207 // (but only if control is smaller than best size).
1208 int bestHeight
= GetBestSize().y
;
1209 int height
= GetSize().y
;
1211 if ( height
< bestHeight
)
1213 // Make very small buttons square, as it makes
1214 // them accommodate arrow image better and still
1217 butWidth
= (height
*butWidth
)/bestHeight
;
1219 butWidth
= butHeight
;
1223 // Adjust button height
1225 butHeight
= m_btnHei
;
1227 // Use size of normal bitmap if...
1230 // button width is set to default and blank button bg is not drawn
1231 if ( m_bmpNormal
.Ok() )
1233 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1234 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1236 // If drawing blank button background, we need to add some margin.
1237 if ( m_blankButtonBg
)
1239 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1240 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1243 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1244 butWidth
= bmpReqWidth
;
1245 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1246 butHeight
= bmpReqHeight
;
1248 // Need to fix height?
1249 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1251 int newY
= butHeight
+(customBorder
*2);
1252 SetClientSize(wxDefaultCoord
,newY
);
1253 if ( m_bmpNormal
.Ok() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1254 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1256 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1262 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1264 m_btnSize
.x
= butWidth
;
1265 m_btnSize
.y
= butHeight
;
1267 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1268 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1269 m_btnArea
.width
= butAreaWid
;
1270 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1272 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1273 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1274 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1275 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1280 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1281 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1286 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1291 wxSize sz
= GetClientSize();
1293 int customBorder
= m_widthCustomBorder
;
1294 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1298 if ( !m_widthCustomPaint
)
1300 // No special custom paint area - we can use 0 left margin
1302 if ( m_text
->SetMargins(0) )
1303 textCtrlXAdjust
= 0;
1304 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1308 // There is special custom paint area - it is better to
1309 // use some margin with the wxTextCtrl.
1310 m_text
->SetMargins(m_marginLeft
);
1311 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1312 m_marginLeft
+ textCtrlXAdjust
;
1315 // Centre textctrl vertically, if needed
1316 #if !TEXTCTRL_TEXT_CENTERED
1317 int tcSizeY
= m_text
->GetBestSize().y
;
1318 int diff0
= sz
.y
- tcSizeY
;
1319 int y
= textCtrlYAdjust
+ (diff0
/2);
1321 wxUnusedVar(textCtrlYAdjust
);
1325 if ( y
< customBorder
)
1330 m_tcArea
.width
- m_tcArea
.x
- x
,
1333 // Make sure textctrl doesn't exceed the bottom custom border
1334 wxSize tsz
= m_text
->GetSize();
1335 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1338 tsz
.y
= tsz
.y
- diff1
- 1;
1339 m_text
->SetSize(tsz
);
1344 // If it has border, have textctrl fill the entire text field.
1345 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1347 m_tcArea
.width
- m_widthCustomPaint
,
1352 wxSize
wxComboCtrlBase::DoGetBestSize() const
1354 wxSize
sizeText(150,0);
1357 sizeText
= m_text
->GetBestSize();
1359 // TODO: Better method to calculate close-to-native control height.
1363 fhei
= (m_font
.GetPointSize()*2) + 5;
1364 else if ( wxNORMAL_FONT
->Ok() )
1365 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1367 fhei
= sizeText
.y
+ 4;
1369 // Need to force height to accomodate bitmap?
1370 int btnSizeY
= m_btnSize
.y
;
1371 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1374 // Control height doesn't depend on border
1377 int border = m_windowStyle & wxBORDER_MASK;
1378 if ( border == wxSIMPLE_BORDER )
1380 else if ( border == wxNO_BORDER )
1381 fhei += (m_widthCustomBorder*2);
1387 // Final adjustments
1393 // these are the numbers from the HIG:
1394 switch ( m_windowVariant
)
1396 case wxWINDOW_VARIANT_NORMAL
:
1400 case wxWINDOW_VARIANT_SMALL
:
1403 case wxWINDOW_VARIANT_MINI
:
1409 fhei
+= 2 * FOCUS_RING
;
1410 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1412 wxSize
ret(width
, fhei
);
1417 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1422 // defined by actual wxComboCtrls
1428 // ----------------------------------------------------------------------------
1429 // standard operations
1430 // ----------------------------------------------------------------------------
1432 bool wxComboCtrlBase::Enable(bool enable
)
1434 if ( !wxControl::Enable(enable
) )
1438 m_btn
->Enable(enable
);
1440 m_text
->Enable(enable
);
1447 bool wxComboCtrlBase::Show(bool show
)
1449 if ( !wxControl::Show(show
) )
1461 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1463 if ( !wxControl::SetFont(font
) )
1468 // Without hiding the wxTextCtrl there would be some
1469 // visible 'flicker' (at least on Windows XP).
1471 m_text
->SetFont(font
);
1480 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1482 wxControl::DoSetToolTip(tooltip
);
1484 // Set tool tip for button and text box
1487 const wxString
&tip
= tooltip
->GetTip();
1488 if ( m_text
) m_text
->SetToolTip(tip
);
1489 if ( m_btn
) m_btn
->SetToolTip(tip
);
1493 if ( m_text
) m_text
->SetToolTip( NULL
);
1494 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1497 #endif // wxUSE_TOOLTIPS
1499 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1501 if ( wxControl::SetForegroundColour(colour
) )
1504 m_text
->SetForegroundColour(colour
);
1510 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1513 m_text
->SetBackgroundColour(colour
);
1515 m_hasTcBgCol
= true;
1519 wxColour
wxComboCtrlBase::GetBackgroundColour() const
1522 return m_text
->GetBackgroundColour();
1526 // ----------------------------------------------------------------------------
1528 // ----------------------------------------------------------------------------
1530 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1531 // prepare combo box background on area in a way typical on platform
1532 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1534 wxSize sz
= GetClientSize();
1536 bool doDrawFocusRect
; // also selected
1538 // For smaller size control (and for disabled background) use less spacing
1542 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1545 isEnabled
= IsEnabled();
1546 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1548 // Windows-style: for smaller size control (and for disabled background) use less spacing
1549 focusSpacingX
= isEnabled
? 2 : 1;
1550 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1554 // Drawing a list item
1555 isEnabled
= true; // they are never disabled
1556 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1562 // Set the background sub-rectangle for selection, disabled etc
1563 wxRect
selRect(rect
);
1564 selRect
.y
+= focusSpacingY
;
1565 selRect
.height
-= (focusSpacingY
*2);
1569 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1570 wcp
+= m_widthCustomPaint
;
1572 selRect
.x
+= wcp
+ focusSpacingX
;
1573 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1578 bool doDrawSelRect
= true;
1580 // Determine foreground colour
1583 if ( doDrawFocusRect
)
1585 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1587 else if ( m_hasFgCol
)
1589 // Honour the custom foreground colour
1590 fgCol
= GetForegroundColour();
1594 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1599 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1602 // Determine background colour
1605 if ( doDrawFocusRect
)
1607 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1609 else if ( m_hasTcBgCol
)
1611 // Honour the custom background colour
1616 #ifndef __WXMAC__ // see note in OnThemeChange
1617 doDrawSelRect
= false;
1618 bgCol
= GetBackgroundColour();
1620 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1626 #ifndef __WXMAC__ // see note in OnThemeChange
1627 bgCol
= GetBackgroundColour();
1629 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1633 dc
.SetTextForeground( fgCol
);
1634 dc
.SetBrush( bgCol
);
1635 if ( doDrawSelRect
)
1638 dc
.DrawRectangle( selRect
);
1641 // Don't clip exactly to the selection rectangle so we can draw
1642 // to the non-selected area in front of it.
1643 wxRect
clipRect(rect
.x
,rect
.y
,
1644 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1645 dc
.SetClippingRegion(clipRect
);
1648 // Save the library size a bit for platforms that re-implement this.
1649 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1654 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1656 int drawState
= m_btnState
;
1658 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1659 GetPopupWindowState() >= Animating
)
1660 drawState
|= wxCONTROL_PRESSED
;
1662 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1663 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1667 // Make sure area is not larger than the control
1668 if ( drawRect
.y
< rect
.y
)
1669 drawRect
.y
= rect
.y
;
1670 if ( drawRect
.height
> rect
.height
)
1671 drawRect
.height
= rect
.height
;
1673 bool enabled
= IsEnabled();
1676 drawState
|= wxCONTROL_DISABLED
;
1678 // Need to clear button background even if m_btn is present
1679 // and also when using custom bitmap for the button
1680 if ( (flags
& Button_PaintBackground
) &&
1681 (!HasTransparentBackground() ||
1682 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1686 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1687 bgCol
= GetParent()->GetBackgroundColour();
1689 bgCol
= GetBackgroundColour();
1693 dc
.DrawRectangle(rect
);
1696 if ( !m_bmpNormal
.Ok() )
1698 if ( flags
& Button_BitmapOnly
)
1701 // Draw standard button
1702 wxRendererNative::Get().DrawComboBoxDropButton(this,
1714 pBmp
= &m_bmpDisabled
;
1715 else if ( m_btnState
& wxCONTROL_PRESSED
)
1716 pBmp
= &m_bmpPressed
;
1717 else if ( m_btnState
& wxCONTROL_CURRENT
)
1720 pBmp
= &m_bmpNormal
;
1722 if ( m_blankButtonBg
)
1724 if ( !(flags
& Button_BitmapOnly
) )
1726 wxRendererNative::Get().DrawPushButton(this,
1733 // Draw bitmap centered in drawRect
1734 dc
.DrawBitmap(*pBmp
,
1735 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1736 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1741 void wxComboCtrlBase::RecalcAndRefresh()
1745 wxSizeEvent
evt(GetSize(),GetId());
1746 GetEventHandler()->ProcessEvent(evt
);
1751 // ----------------------------------------------------------------------------
1752 // miscellaneous event handlers
1753 // ----------------------------------------------------------------------------
1755 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1757 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1759 if ( m_ignoreEvtText
> 0 )
1766 // Change event id, object and string before relaying it forward
1767 event
.SetId(GetId());
1768 wxString s
= event
.GetString();
1769 event
.SetEventObject(this);
1774 // call if cursor is on button area or mouse is captured for the button
1775 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1778 int type
= event
.GetEventType();
1780 if ( type
== wxEVT_MOTION
)
1782 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1783 IsPopupWindowState(Hidden
) )
1785 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1787 // Mouse hover begins
1788 m_btnState
|= wxCONTROL_CURRENT
;
1789 if ( HasCapture() ) // Retain pressed state.
1790 m_btnState
|= wxCONTROL_PRESSED
;
1794 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1797 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1801 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1803 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1805 m_btnState
|= wxCONTROL_PRESSED
;
1808 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1811 // If showing popup now, do not capture mouse or there will be interference
1815 else if ( type
== wxEVT_LEFT_UP
)
1818 // Only accept event if mouse was left-press was previously accepted
1822 if ( m_btnState
& wxCONTROL_PRESSED
)
1824 // If mouse was inside, fire the click event.
1825 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1827 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1831 m_btnState
&= ~(wxCONTROL_PRESSED
);
1835 else if ( type
== wxEVT_LEAVE_WINDOW
)
1837 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1839 m_btnState
&= ~(wxCONTROL_CURRENT
);
1842 if ( IsPopupWindowState(Hidden
) )
1844 m_btnState
&= ~(wxCONTROL_PRESSED
);
1852 // Never have 'hot' state when popup is being shown
1853 // (this is mostly needed because of the animation).
1854 if ( !IsPopupWindowState(Hidden
) )
1855 m_btnState
&= ~wxCONTROL_CURRENT
;
1860 // returns true if event was consumed or filtered
1861 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1862 int WXUNUSED(flags
) )
1864 wxLongLong t
= ::wxGetLocalTimeMillis();
1865 int evtType
= event
.GetEventType();
1867 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1868 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1870 if ( IsPopupWindowState(Visible
) &&
1871 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1879 // Filter out clicks on button immediately after popup dismiss
1880 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1882 event
.SetEventType(0);
1889 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1891 int evtType
= event
.GetEventType();
1893 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1894 (m_windowStyle
& wxCB_READONLY
) )
1896 if ( GetPopupWindowState() >= Animating
)
1898 #if USES_WXPOPUPWINDOW
1899 // Click here always hides the popup.
1900 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1906 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1908 // In read-only mode, clicking the text is the
1909 // same as clicking the button.
1912 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1914 //if ( m_popupInterface->CycleValue() )
1916 if ( m_popupInterface
)
1917 m_popupInterface
->OnComboDoubleClick();
1921 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1923 if ( IsPopupShown() )
1925 // relay (some) mouse events to the popup
1926 m_popup
->GetEventHandler()->ProcessEvent(event
);
1928 else if ( event
.GetWheelAxis() == 0 &&
1929 event
.GetWheelRotation() != 0 &&
1930 event
.GetModifiers() == 0 )
1932 // Translate mousewheel actions into key up/down. This is
1933 // the simplest way of getting native behaviour: scrolling the
1934 // wheel moves selection up/down by one item.
1935 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1936 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1939 GetEventHandler()->ProcessEvent(kevent
);
1952 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1954 if ( IsPopupShown() )
1956 // pass it to the popped up control
1957 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1961 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1963 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1965 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1969 if ( IsKeyPopupToggle(event
) )
1975 int comboStyle
= GetWindowStyle();
1976 wxComboPopup
* popupInterface
= GetPopupControl();
1978 if ( !popupInterface
)
1984 int keycode
= event
.GetKeyCode();
1986 if ( (comboStyle
& wxCB_READONLY
) ||
1987 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1989 popupInterface
->OnComboKeyEvent(event
);
1996 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
1998 if ( IsPopupShown() )
2000 // pass it to the popped up control
2001 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
2005 wxComboPopup
* popupInterface
= GetPopupControl();
2006 if ( popupInterface
)
2008 popupInterface
->OnComboCharEvent(event
);
2017 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
2019 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2021 wxWindow
* tc
= GetTextCtrl();
2022 if ( tc
&& tc
!= DoFindFocus() )
2031 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2035 m_resetFocus
= false;
2036 wxWindow
* tc
= GetTextCtrl();
2042 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2045 // left margin may also have changed
2046 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2047 m_marginLeft
= GetNativeTextIndent();
2051 // ----------------------------------------------------------------------------
2053 // ----------------------------------------------------------------------------
2055 // Create popup window and the child control
2056 void wxComboCtrlBase::CreatePopup()
2058 wxComboPopup
* popupInterface
= m_popupInterface
;
2063 #ifdef wxComboPopupWindowBase2
2064 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2066 #if !USES_GENERICTLW
2067 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2069 int tlwFlags
= wxNO_BORDER
;
2070 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2071 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2074 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2075 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2076 wxPoint(-21,-21), wxSize(20, 20),
2079 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2080 wxPoint(-21,-21), wxSize(20, 20),
2084 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2087 #endif // wxComboPopupWindowBase2
2089 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2090 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2092 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2093 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2096 popupInterface
->Create(m_winPopup
);
2097 m_popup
= popup
= popupInterface
->GetControl();
2099 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2100 popup
->PushEventHandler( m_popupEvtHandler
);
2102 // This may be helpful on some platforms
2103 // (eg. it bypasses a wxGTK popupwindow bug where
2104 // window is not initially hidden when it should be)
2107 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2110 // Destroy popup window and the child control
2111 void wxComboCtrlBase::DestroyPopup()
2116 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2118 wxDELETE(m_popupEvtHandler
);
2120 if ( m_popupInterface
)
2122 // NB: DestroyPopup() performs 'delete this'.
2123 m_popupInterface
->DestroyPopup();
2124 m_popupInterface
= NULL
;
2129 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2130 wxDELETE(m_popupWinEvtHandler
);
2131 m_winPopup
->Destroy();
2138 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2140 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2144 iface
->InitBase(this);
2147 m_popupInterface
= iface
;
2149 if ( !iface
->LazyCreate() )
2158 // This must be done after creation
2159 if ( !m_valueString
.empty() )
2161 iface
->SetStringValue(m_valueString
);
2166 // Ensures there is atleast the default popup
2167 void wxComboCtrlBase::EnsurePopupControl()
2169 if ( !m_popupInterface
)
2170 SetPopupControl(NULL
);
2173 void wxComboCtrlBase::OnButtonClick()
2175 // Derived classes can override this method for totally custom
2177 switch ( GetPopupWindowState() )
2194 void wxComboCtrlBase::Popup()
2196 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2197 event
.SetEventObject(this);
2198 HandleWindowEvent(event
);
2203 void wxComboCtrlBase::ShowPopup()
2205 EnsurePopupControl();
2206 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2208 if ( IsPopupWindowState(Animating
) )
2213 // Space above and below
2219 wxSize ctrlSz
= GetSize();
2221 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2222 scrPos
= GetParent()->ClientToScreen(GetPosition());
2224 spaceAbove
= scrPos
.y
;
2225 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2227 maxHeightPopup
= spaceBelow
;
2228 if ( spaceAbove
> spaceBelow
)
2229 maxHeightPopup
= spaceAbove
;
2232 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2234 if ( widthPopup
< m_widthMinPopup
)
2235 widthPopup
= m_widthMinPopup
;
2237 wxWindow
* winPopup
= m_winPopup
;
2240 // Need to disable tab traversal of parent
2242 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2243 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2244 // that if transient popup is open, then tab traversal is to be ignored.
2245 // However, I think this code would still be needed for cases where
2246 // transient popup doesn't work yet (wxWinCE?).
2247 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2248 wxWindow
* parent
= mainCtrl
->GetParent();
2249 int parentFlags
= parent
->GetWindowStyle();
2250 if ( parentFlags
& wxTAB_TRAVERSAL
)
2252 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2253 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2259 winPopup
= m_winPopup
;
2269 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2271 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2272 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2275 popup
->SetSize(adjustedSize
);
2277 m_popupInterface
->OnPopup();
2280 // Reposition and resize popup window
2283 wxSize szp
= popup
->GetSize();
2286 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2288 // Default anchor is wxLEFT
2289 int anchorSide
= m_anchorSide
;
2291 anchorSide
= wxLEFT
;
2293 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2294 int leftX
= scrPos
.x
- m_extLeft
;
2296 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2299 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2301 // If there is not enough horizontal space, anchor on the other side.
2302 // If there is no space even then, place the popup at x 0.
2303 if ( anchorSide
== wxRIGHT
)
2307 if ( (leftX
+szp
.x
) < screenWidth
)
2308 anchorSide
= wxLEFT
;
2315 if ( (leftX
+szp
.x
) >= screenWidth
)
2318 anchorSide
= wxRIGHT
;
2324 // Select x coordinate according to the anchor side
2325 if ( anchorSide
== wxRIGHT
)
2327 else if ( anchorSide
== wxLEFT
)
2332 int showFlags
= CanDeferShow
;
2334 if ( spaceBelow
< szp
.y
)
2336 popupY
= scrPos
.y
- szp
.y
;
2337 showFlags
|= ShowAbove
;
2340 #if INSTALL_TOPLEV_HANDLER
2341 // Put top level window event handler into place
2342 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2344 if ( !m_toplevEvtHandler
)
2345 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2347 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2349 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2350 toplev
->PushEventHandler( m_toplevEvtHandler
);
2354 // Set string selection (must be this way instead of SetStringSelection)
2357 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2358 m_text
->SelectAll();
2360 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2364 // This is neede since focus/selection indication may change when popup is shown
2368 // This must be after SetStringValue
2369 m_popupWinState
= Animating
;
2371 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2374 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2375 AnimateShow( popupWinRect
, showFlags
) )
2377 DoShowPopup( popupWinRect
, showFlags
);
2381 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2386 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2388 wxWindow
* winPopup
= m_winPopup
;
2390 if ( IsPopupWindowState(Animating
) )
2392 // Make sure the popup window is shown in the right position.
2393 // Should not matter even if animation already did this.
2395 // Some platforms (GTK) may like SetSize and Move to be separate
2396 // (though the bug was probably fixed).
2397 winPopup
->SetSize( rect
);
2399 #if USES_WXPOPUPTRANSIENTWINDOW
2400 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2401 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2406 m_popupWinState
= Visible
;
2408 // If popup window was a generic top-level window, or the
2409 // wxPopupWindow implemenation on this platform is classified as
2410 // perfect, then we should be able to safely set focus to the popup
2412 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2413 m_popup
->SetFocus();
2415 else if ( IsPopupWindowState(Hidden
) )
2417 // Animation was aborted
2419 wxASSERT( !winPopup
->IsShown() );
2421 m_popupWinState
= Hidden
;
2427 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2429 // Just in case, avoid double dismiss
2430 if ( IsPopupWindowState(Hidden
) )
2433 // This must be set before focus - otherwise there will be recursive
2434 // OnPopupDismisses.
2435 m_popupWinState
= Hidden
;
2438 m_winPopup
->Disable();
2440 // Inform popup control itself
2441 m_popupInterface
->OnDismiss();
2443 if ( m_popupEvtHandler
)
2444 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2446 #if INSTALL_TOPLEV_HANDLER
2447 // Remove top level window event handler
2448 if ( m_toplevEvtHandler
)
2450 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2452 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2456 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2458 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2459 m_timeCanAcceptClick
+= 150;
2461 // If cursor not on dropdown button, then clear its state
2462 // (technically not required by all ports, but do it for all just in case)
2463 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2466 // Return parent's tab traversal flag.
2467 // See ShowPopup for notes.
2468 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2470 wxWindow
* parent
= GetParent();
2471 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2472 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2475 // refresh control (necessary even if m_text)
2480 if ( generateEvent
)
2482 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2483 event
.SetEventObject(this);
2484 HandleWindowEvent(event
);
2488 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2490 // Should be able to call this without popup interface
2491 if ( IsPopupWindowState(Hidden
) )
2494 // transfer value and show it in textctrl, if any
2495 if ( !IsPopupWindowState(Animating
) )
2496 SetValueByUser( m_popupInterface
->GetStringValue() );
2500 OnPopupDismiss(generateEvent
);
2503 // ----------------------------------------------------------------------------
2504 // customization methods
2505 // ----------------------------------------------------------------------------
2507 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2508 int side
, int spacingX
)
2513 m_btnSpacingX
= spacingX
;
2515 if ( width
> 0 || height
> 0 || spacingX
)
2516 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2521 wxSize
wxComboCtrlBase::GetButtonSize()
2523 if ( m_btnSize
.x
> 0 )
2526 wxSize
retSize(m_btnWid
,m_btnHei
);
2528 // Need to call CalculateAreas now if button size is
2529 // is not explicitly specified.
2530 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2534 retSize
= m_btnSize
;
2540 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2542 const wxBitmap
& bmpPressed
,
2543 const wxBitmap
& bmpHover
,
2544 const wxBitmap
& bmpDisabled
)
2546 m_bmpNormal
= bmpNormal
;
2547 m_blankButtonBg
= blankButtonBg
;
2549 if ( bmpPressed
.Ok() )
2550 m_bmpPressed
= bmpPressed
;
2552 m_bmpPressed
= bmpNormal
;
2554 if ( bmpHover
.Ok() )
2555 m_bmpHover
= bmpHover
;
2557 m_bmpHover
= bmpNormal
;
2559 if ( bmpDisabled
.Ok() )
2560 m_bmpDisabled
= bmpDisabled
;
2562 m_bmpDisabled
= bmpNormal
;
2567 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2571 // move textctrl accordingly
2572 wxRect r
= m_text
->GetRect();
2573 int inc
= width
- m_widthCustomPaint
;
2576 m_text
->SetSize( r
);
2579 m_widthCustomPaint
= width
;
2584 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2586 // For general sanity's sake, we ignore top margin. Instead
2587 // we will always try to center the text vertically.
2590 if ( margins
.x
!= -1 )
2592 m_marginLeft
= margins
.x
;
2593 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2597 m_marginLeft
= GetNativeTextIndent();
2598 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2601 if ( margins
.y
!= -1 )
2611 wxPoint
wxComboCtrlBase::DoGetMargins() const
2613 return wxPoint(m_marginLeft
, -1);
2616 #if WXWIN_COMPATIBILITY_2_8
2617 void wxComboCtrlBase::SetTextIndent( int indent
)
2621 m_marginLeft
= GetNativeTextIndent();
2622 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2626 m_marginLeft
= indent
;
2627 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2633 wxCoord
wxComboCtrlBase::GetTextIndent() const
2635 return m_marginLeft
;
2639 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2641 return DEFAULT_TEXT_INDENT
;
2644 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2646 m_textCtrlStyle
= style
;
2649 m_text
->SetWindowStyle(style
);
2652 // ----------------------------------------------------------------------------
2653 // wxTextEntry interface
2654 // ----------------------------------------------------------------------------
2656 wxString
wxComboCtrlBase::DoGetValue() const
2659 return m_text
->GetValue();
2660 return m_valueString
;
2663 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2666 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2669 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2671 // Note: before wxComboCtrl inherited from wxTextEntry,
2672 // this code used to be in SetValueWithEvent().
2674 // Since wxComboPopup may want to paint the combo as well, we need
2675 // to set the string value here (as well as sometimes in ShowPopup).
2676 if ( m_valueString
!= value
)
2679 wxString trueValue
= value
;
2681 // Conform to wxComboBox behaviour: read-only control can only accept
2682 // valid list items and empty string
2683 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2685 found
= m_popupInterface
->FindItem(value
,
2691 m_valueString
= trueValue
;
2693 EnsurePopupControl();
2695 if ( m_popupInterface
)
2696 m_popupInterface
->SetStringValue(trueValue
);
2703 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2705 // NB: Order of function calls is important here. Otherwise
2706 // the SelectAll() may not work.
2710 m_text
->SetValue(value
);
2712 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2713 m_text
->SelectAll();
2719 // In this SetValue variant wxComboPopup::SetStringValue is not called
2720 void wxComboCtrlBase::SetText(const wxString
& value
)
2722 // Unlike in SetValue(), this must be called here or
2723 // the behaviour will no be consistent in readonlys.
2724 EnsurePopupControl();
2726 m_valueString
= value
;
2731 m_text
->SetValue( value
);
2737 void wxComboCtrlBase::Copy()
2743 void wxComboCtrlBase::Cut()
2749 void wxComboCtrlBase::Paste()
2755 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2758 m_text
->SetInsertionPoint(pos
);
2761 long wxComboCtrlBase::GetInsertionPoint() const
2764 return m_text
->GetInsertionPoint();
2769 long wxComboCtrlBase::GetLastPosition() const
2772 return m_text
->GetLastPosition();
2777 void wxComboCtrlBase::WriteText(const wxString
& text
)
2781 m_text
->WriteText(text
);
2782 OnSetValue(m_text
->GetValue());
2790 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2794 if ( flags
& SetValue_SendEvent
)
2795 m_text
->SetValue(value
);
2797 m_text
->ChangeValue(value
);
2803 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2807 m_text
->Replace(from
, to
, value
);
2808 OnSetValue(m_text
->GetValue());
2812 void wxComboCtrlBase::Remove(long from
, long to
)
2816 m_text
->Remove(from
, to
);
2817 OnSetValue(m_text
->GetValue());
2821 void wxComboCtrlBase::SetSelection(long from
, long to
)
2824 m_text
->SetSelection(from
, to
);
2827 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2831 m_text
->GetSelection(from
, to
);
2840 bool wxComboCtrlBase::IsEditable() const
2843 return m_text
->IsEditable();
2847 void wxComboCtrlBase::SetEditable(bool editable
)
2850 m_text
->SetEditable(editable
);
2853 void wxComboCtrlBase::Undo()
2859 void wxComboCtrlBase::Redo()
2865 bool wxComboCtrlBase::CanUndo() const
2868 return m_text
->CanUndo();
2873 bool wxComboCtrlBase::CanRedo() const
2876 return m_text
->CanRedo();
2881 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2886 res
= m_text
->SetHint(hint
);
2891 wxString
wxComboCtrlBase::GetHint() const
2896 #endif // wxUSE_COMBOCTRL