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 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox
, wxChoice
, "wx/combobox.h")
86 wxBEGIN_PROPERTIES_TABLE(wxComboBox
)
87 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_COMBOBOX_SELECTED
, wxCommandEvent
)
88 wxEVENT_PROPERTY( TextEnter
, wxEVT_COMMAND_TEXT_ENTER
, wxCommandEvent
)
91 wxPROPERTY( Font
, wxFont
, SetFont
, GetFont
, wxEMPTY_PARAMETER_VALUE
, \
92 0 /*flags*/, wxT("Helpstring"), wxT("group"))
93 wxPROPERTY_COLLECTION( Choices
, wxArrayString
, wxString
, AppendString
, \
94 GetStrings
, 0 /*flags*/, wxT("Helpstring"), wxT("group"))
95 wxPROPERTY( Value
,wxString
, SetValue
, GetValue
, wxEMPTY_PARAMETER_VALUE
, \
96 0 /*flags*/, wxT("Helpstring"), wxT("group"))
97 wxPROPERTY( Selection
,int, SetSelection
, GetSelection
, wxEMPTY_PARAMETER_VALUE
, \
98 0 /*flags*/, wxT("Helpstring"), wxT("group"))
100 wxPROPERTY_FLAGS( WindowStyle
, wxComboBoxStyle
, long, SetWindowStyleFlag
, \
101 GetWindowStyleFlag
, wxEMPTY_PARAMETER_VALUE
, 0 /*flags*/, \
102 wxT("Helpstring"), wxT("group")) // style
103 wxEND_PROPERTIES_TABLE()
105 wxEMPTY_HANDLERS_TABLE(wxComboBox
)
107 wxCONSTRUCTOR_5( wxComboBox
, wxWindow
*, Parent
, wxWindowID
, Id
, \
108 wxString
, Value
, wxPoint
, Position
, wxSize
, Size
)
111 // ----------------------------------------------------------------------------
113 #define DEFAULT_DROPBUTTON_WIDTH 19
115 #define BMP_BUTTON_MARGIN 4
117 #define DEFAULT_POPUP_HEIGHT 400
119 #define DEFAULT_TEXT_INDENT 3
121 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
124 #if defined(__WXMSW__)
126 // Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow
127 #include "wx/frame.h"
128 #define wxCC_GENERIC_TLW_IS_FRAME
129 #define wxComboCtrlGenericTLW wxFrame
131 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
132 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
133 // native controls work on it like normal.
134 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
135 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
136 #define FOCUS_RING 0 // No focus ring on wxMSW
138 //#undef wxUSE_POPUPWIN
139 //#define wxUSE_POPUPWIN 0
141 #elif defined(__WXGTK__)
143 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
144 // this bug: If wxDialog is hidden, its position becomes corrupt
145 // between hide and next show, but without internal coordinates being
146 // reflected (or something like that - atleast commenting out ->Hide()
147 // seemed to eliminate the position change).
149 #include "wx/dialog.h"
150 #define wxCC_GENERIC_TLW_IS_DIALOG
151 #define wxComboCtrlGenericTLW wxDialog
153 #if defined(__WXGTK20__)
154 # include "wx/gtk/private.h"
156 # include "wx/gtk1/private.h"
159 // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a
160 // 'perfect' popup, as it can succesfully host child controls even in
161 // popups that are shown in modal dialogs.
163 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
164 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
165 // native controls work on it like normal.
166 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
167 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
168 #define FOCUS_RING 0 // No focus ring on wxGTK
170 #elif defined(__WXMAC__)
172 #include "wx/nonownedwnd.h"
173 #define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
174 #define wxComboCtrlGenericTLW wxNonOwnedWindow
176 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
177 #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common
178 // native controls work on it like normal.
179 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
180 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
181 #define FOCUS_RING 3 // Reserve room for the textctrl's focus ring to display
183 #undef DEFAULT_DROPBUTTON_WIDTH
184 #define DEFAULT_DROPBUTTON_WIDTH 22
186 #define COMBO_MARGIN FOCUS_RING
190 #include "wx/dialog.h"
191 #define wxCC_GENERIC_TLW_IS_DIALOG
192 #define wxComboCtrlGenericTLW wxDialog
194 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
195 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
196 // native controls work on it like normal.
197 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
198 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
204 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
205 // what the wxUSE_POPUPWIN says.
206 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
207 #if (!defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXMAC__)) || defined(__WXWINCE__)
208 #undef wxUSE_POPUPWIN
209 #define wxUSE_POPUPWIN 0
214 #include "wx/popupwin.h"
216 #undef USE_TRANSIENT_POPUP
217 #define USE_TRANSIENT_POPUP 0
221 // Define different types of popup windows
225 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
226 POPUPWIN_WXPOPUPWINDOW
= 2,
227 POPUPWIN_GENERICTLW
= 3
231 #if USE_TRANSIENT_POPUP
232 // wxPopupTransientWindow is implemented
234 #define wxComboPopupWindowBase wxPopupTransientWindow
235 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
236 #define USES_WXPOPUPTRANSIENTWINDOW 1
238 #if TRANSIENT_POPUPWIN_IS_PERFECT
240 #elif POPUPWIN_IS_PERFECT
241 #define wxComboPopupWindowBase2 wxPopupWindow
242 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
243 #define USES_WXPOPUPWINDOW 1
245 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
246 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
247 #define USES_GENERICTLW 1
251 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
253 #define wxComboPopupWindowBase wxPopupWindow
254 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
255 #define USES_WXPOPUPWINDOW 1
257 #if !POPUPWIN_IS_PERFECT
258 #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW
259 #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW
260 #define USES_GENERICTLW 1
264 // wxPopupWindow is not implemented
266 #define wxComboPopupWindowBase wxComboCtrlGenericTLW
267 #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW
268 #define USES_GENERICTLW 1
273 #ifndef USES_WXPOPUPTRANSIENTWINDOW
274 #define USES_WXPOPUPTRANSIENTWINDOW 0
277 #ifndef USES_WXPOPUPWINDOW
278 #define USES_WXPOPUPWINDOW 0
281 #ifndef USES_GENERICTLW
282 #define USES_GENERICTLW 0
286 #if USES_WXPOPUPWINDOW
287 #define INSTALL_TOPLEV_HANDLER 1
289 #define INSTALL_TOPLEV_HANDLER 0
293 // Returns true if given popup window type can be classified as perfect
295 static inline bool IsPopupWinTypePerfect( wxByte popupWinType
)
297 #if POPUPWIN_IS_PERFECT && TRANSIENT_POPUPWIN_IS_PERFECT
298 wxUnusedVar(popupWinType
);
301 return ( popupWinType
== POPUPWIN_GENERICTLW
302 #if POPUPWIN_IS_PERFECT
303 || popupWinType
== POPUPWIN_WXPOPUPWINDOW
305 #if TRANSIENT_POPUPWIN_IS_PERFECT
306 || popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
315 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
319 // ----------------------------------------------------------------------------
320 // wxComboFrameEventHandler takes care of hiding the popup when events happen
321 // in its top level parent.
322 // ----------------------------------------------------------------------------
324 #if INSTALL_TOPLEV_HANDLER
327 // This will no longer be necessary after wxTransientPopupWindow
328 // works well on all platforms.
331 class wxComboFrameEventHandler
: public wxEvtHandler
334 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
335 virtual ~wxComboFrameEventHandler();
339 void OnIdle( wxIdleEvent
& event
);
340 void OnMouseEvent( wxMouseEvent
& event
);
341 void OnActivate( wxActivateEvent
& event
);
342 void OnResize( wxSizeEvent
& event
);
343 void OnMove( wxMoveEvent
& event
);
344 void OnMenuEvent( wxMenuEvent
& event
);
345 void OnClose( wxCloseEvent
& event
);
348 wxWindow
* m_focusStart
;
349 wxComboCtrlBase
* m_combo
;
352 DECLARE_EVENT_TABLE()
355 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
356 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
357 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
358 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
359 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
360 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
361 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
362 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
363 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
364 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
367 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
373 wxComboFrameEventHandler::~wxComboFrameEventHandler()
377 void wxComboFrameEventHandler::OnPopup()
379 m_focusStart
= ::wxWindow::FindFocus();
382 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
384 wxWindow
* winFocused
= ::wxWindow::FindFocus();
386 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
387 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
390 winFocused
!= m_focusStart
&&
391 winFocused
!= popup
&&
392 winFocused
->GetParent() != popup
&&
393 winFocused
!= winpopup
&&
394 winFocused
->GetParent() != winpopup
&&
395 winFocused
!= m_combo
&&
396 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
399 m_combo
->HidePopup(true);
405 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
407 m_combo
->HidePopup(true);
411 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
413 m_combo
->HidePopup(true);
417 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
419 m_combo
->HidePopup(true);
423 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
425 m_combo
->HidePopup(true);
429 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
431 m_combo
->HidePopup(true);
435 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
437 m_combo
->HidePopup(true);
441 #endif // INSTALL_TOPLEV_HANDLER
443 // ----------------------------------------------------------------------------
444 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
446 // ----------------------------------------------------------------------------
448 class wxComboPopupWindow
: public wxComboPopupWindowBase
452 wxComboPopupWindow( wxComboCtrlBase
*parent
,
454 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
455 : wxComboPopupWindowBase(parent
,style
)
457 : wxComboPopupWindowBase(parent
,
468 #if USES_WXPOPUPTRANSIENTWINDOW
469 virtual bool Show( bool show
);
470 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
472 virtual void OnDismiss();
480 #if USES_WXPOPUPTRANSIENTWINDOW
481 bool wxComboPopupWindow::Show( bool show
)
483 // Guard against recursion
485 return wxComboPopupWindowBase::Show(show
);
489 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
491 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
493 if ( show
!= ptw
->IsShown() )
496 // We used to do wxPopupTransientWindow::Popup here,
497 // but this would hide normal Show, which we are
498 // also going to need.
509 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
511 return wxPopupTransientWindow::ProcessLeftDown(event
);
514 // First thing that happens when a transient popup closes is that this method gets called.
515 void wxComboPopupWindow::OnDismiss()
517 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
518 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
519 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
521 combo
->OnPopupDismiss(true);
523 #endif // USES_WXPOPUPTRANSIENTWINDOW
526 // ----------------------------------------------------------------------------
527 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
528 // of a popup window. It is separate so we can have different types
530 // ----------------------------------------------------------------------------
532 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
536 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
541 void OnSizeEvent( wxSizeEvent
& event
);
542 void OnKeyEvent(wxKeyEvent
& event
);
544 void OnActivate( wxActivateEvent
& event
);
548 wxComboCtrlBase
* m_combo
;
550 DECLARE_EVENT_TABLE()
554 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
555 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
556 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
557 EVT_CHAR(wxComboPopupWindowEvtHandler::OnKeyEvent
)
559 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
561 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
565 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
567 // Block the event so that the popup control does not get auto-resized.
570 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
572 // Relay keyboard event to the main child controls
573 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
574 wxWindowList::iterator node
= children
.begin();
575 wxWindow
* child
= (wxWindow
*)*node
;
576 child
->GetEventHandler()->ProcessEvent(event
);
580 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
582 if ( !event
.GetActive() )
584 // Tell combo control that we are dismissed.
585 m_combo
->HidePopup(true);
593 // ----------------------------------------------------------------------------
596 // ----------------------------------------------------------------------------
598 wxComboPopup::~wxComboPopup()
602 void wxComboPopup::OnPopup()
606 void wxComboPopup::OnDismiss()
610 wxComboCtrl
* wxComboPopup::GetComboCtrl() const
612 return wxStaticCast(m_combo
, wxComboCtrl
);
615 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
617 int WXUNUSED(maxHeight
) )
619 return wxSize(minWidth
,prefHeight
);
622 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
623 wxDC
& dc
, const wxRect
& rect
)
625 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
627 combo
->PrepareBackground(dc
,rect
,0);
629 dc
.DrawText( combo
->GetValue(),
630 rect
.x
+ combo
->m_marginLeft
,
631 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
635 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
637 DefaultPaintComboControl(m_combo
,dc
,rect
);
640 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
645 void wxComboPopup::OnComboCharEvent( wxKeyEvent
& event
)
650 void wxComboPopup::OnComboDoubleClick()
654 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
658 bool wxComboPopup::FindItem(const wxString
& WXUNUSED(item
),
659 wxString
* WXUNUSED(trueItem
))
664 bool wxComboPopup::LazyCreate()
669 void wxComboPopup::Dismiss()
671 m_combo
->HidePopup(true);
674 // ----------------------------------------------------------------------------
676 // ----------------------------------------------------------------------------
679 // This is pushed to the event handler queue of the child textctrl.
681 class wxComboBoxExtraInputHandler
: public wxEvtHandler
685 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
690 virtual ~wxComboBoxExtraInputHandler() { }
691 void OnKey(wxKeyEvent
& event
);
692 void OnFocus(wxFocusEvent
& event
);
695 wxComboCtrlBase
* m_combo
;
698 DECLARE_EVENT_TABLE()
702 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
703 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
704 EVT_KEY_UP(wxComboBoxExtraInputHandler::OnKey
)
705 EVT_CHAR(wxComboBoxExtraInputHandler::OnKey
)
706 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
707 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
711 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
713 // Let the wxComboCtrl event handler have a go first.
714 wxComboCtrlBase
* combo
= m_combo
;
716 wxKeyEvent
redirectedEvent(event
);
717 redirectedEvent
.SetId(combo
->GetId());
718 redirectedEvent
.SetEventObject(combo
);
720 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
722 // Don't let TAB through to the text ctrl - looks ugly
723 if ( event
.GetKeyCode() != WXK_TAB
)
728 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
730 // FIXME: This code does run when control is clicked,
731 // yet on Windows it doesn't select all the text.
732 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
733 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
735 if ( m_combo
->GetTextCtrl() )
736 m_combo
->GetTextCtrl()->SelectAll();
738 m_combo
->SetSelection(-1,-1);
741 // Send focus indication to parent.
742 // NB: This is needed for cases where the textctrl gets focus
743 // instead of its parent. While this may trigger multiple
744 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
745 // from combo's focus event handler), they should be quite
747 wxFocusEvent
evt2(event
);
748 evt2
.SetId(m_combo
->GetId());
749 evt2
.SetEventObject(m_combo
);
750 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
757 // This is pushed to the event handler queue of the control in popup.
760 class wxComboPopupEvtHandler
: public wxEvtHandler
764 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
768 m_beenInside
= false;
770 // Let's make it so that the popup control will not receive mouse
771 // events until mouse left button has been up.
772 m_blockEventsToPopup
= true;
774 virtual ~wxComboPopupEvtHandler() { }
776 void OnMouseEvent( wxMouseEvent
& event
);
778 // Called from wxComboCtrlBase::OnPopupDismiss
779 void OnPopupDismiss()
781 m_beenInside
= false;
782 m_blockEventsToPopup
= true;
786 wxComboCtrlBase
* m_combo
;
789 bool m_blockEventsToPopup
;
792 DECLARE_EVENT_TABLE()
796 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
797 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler::OnMouseEvent
)
801 void wxComboPopupEvtHandler::OnMouseEvent( wxMouseEvent
& event
)
803 wxPoint pt
= event
.GetPosition();
804 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
805 int evtType
= event
.GetEventType();
806 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
807 bool relayToButton
= false;
811 if ( !isInside
|| !m_combo
->IsPopupShown() )
813 // Mouse is outside the popup or popup is not actually shown (yet)
815 if ( evtType
== wxEVT_MOTION
||
816 evtType
== wxEVT_LEFT_DOWN
||
817 evtType
== wxEVT_LEFT_UP
||
818 evtType
== wxEVT_RIGHT_DOWN
)
820 // Block motion and click events outside the popup
826 // Mouse is inside the popup, which is fully shown
830 // Do not let the popup control respond to mouse events until
831 // mouse press used to display the popup has been lifted. This
832 // is important for users with slower mouse fingers or mouse
833 // drivers. Note that we have some redundancy here, just in
834 // case the popup is some native control that does not emit all
835 // mouse event types.
836 if ( evtType
== wxEVT_MOTION
)
838 if ( m_blockEventsToPopup
)
840 if ( event
.LeftIsDown() )
843 m_blockEventsToPopup
= false;
846 else if ( evtType
== wxEVT_LEFT_DOWN
)
848 if ( m_blockEventsToPopup
)
849 m_blockEventsToPopup
= false;
851 else if ( evtType
== wxEVT_LEFT_UP
)
853 if ( m_blockEventsToPopup
)
855 // On first left up, stop blocking mouse events (but still
857 m_blockEventsToPopup
= false;
860 // Also, this button press was (probably) used to display
861 // the popup, so relay it back to the drop-down button
862 // (which supposedly originated it). This is necessary to
863 // refresh it properly.
864 relayToButton
= true;
867 else if ( m_blockEventsToPopup
)
874 // Some mouse events to popup that happen outside it, before cursor
875 // has been inside the popup, need to be ignored by it but relayed to
878 if ( evtType
== wxEVT_LEFT_UP
)
880 if ( !m_combo
->IsPopupShown() )
883 relayToButton
= true;
885 else if ( !isInside
&& !m_beenInside
)
887 // Popup is shown but the cursor is not inside, nor it has been
888 relayToButton
= true;
894 wxWindow
* btn
= m_combo
->GetButton();
896 btn
->GetEventHandler()->ProcessEvent(event
);
898 // Bypass the event handling mechanism. Using it would be
899 // confusing for the platform-specific wxComboCtrl
901 m_combo
->HandleButtonMouseEvent(event
, 0);
905 // ----------------------------------------------------------------------------
906 // wxComboCtrlTextCtrl
907 // ----------------------------------------------------------------------------
909 class wxComboCtrlTextCtrl
: public wxTextCtrl
912 wxComboCtrlTextCtrl() : wxTextCtrl() { }
913 virtual ~wxComboCtrlTextCtrl() { }
915 virtual wxWindow
*GetMainWindowOfCompositeControl()
917 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
919 // Returning this instead of just 'parent' lets FindFocus work
920 // correctly even when parent control is a child of a composite
921 // generic control (as is case with wxGenericDatePickerCtrl).
922 return combo
->GetMainWindowOfCompositeControl();
926 // ----------------------------------------------------------------------------
928 // ----------------------------------------------------------------------------
931 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
932 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
933 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
934 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
935 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
936 EVT_IDLE(wxComboCtrlBase::OnIdleEvent
)
937 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
938 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
939 EVT_CHAR(wxComboCtrlBase::OnCharEvent
)
940 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
941 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
945 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
947 void wxComboCtrlBase::Init()
951 m_popupWinState
= Hidden
;
954 m_popupInterface
= NULL
;
956 m_popupEvtHandler
= NULL
;
957 m_textEvtHandler
= NULL
;
959 #if INSTALL_TOPLEV_HANDLER
960 m_toplevEvtHandler
= NULL
;
963 m_mainCtrlWnd
= this;
966 m_widthMinPopup
= -1;
968 m_widthCustomPaint
= 0;
969 m_widthCustomBorder
= 0;
973 m_blankButtonBg
= false;
975 m_popupWinType
= POPUPWIN_NONE
;
976 m_btnWid
= m_btnHei
= -1;
985 m_timeCanAcceptClick
= 0;
987 m_resetFocus
= false;
990 bool wxComboCtrlBase::Create(wxWindow
*parent
,
992 const wxString
& value
,
996 const wxValidator
& validator
,
997 const wxString
& name
)
999 if ( !wxControl::Create(parent
,
1003 style
| wxWANTS_CHARS
,
1008 m_valueString
= value
;
1012 m_marginLeft
= GetNativeTextIndent();
1014 m_iFlags
|= wxCC_IFLAG_CREATED
;
1016 // If x and y indicate valid size, wxSizeEvent won't be
1017 // emitted automatically, so we need to add artifical one.
1018 if ( size
.x
> 0 && size
.y
> 0 )
1020 wxSizeEvent
evt(size
,GetId());
1021 GetEventHandler()->AddPendingEvent(evt
);
1027 void wxComboCtrlBase::InstallInputHandlers()
1031 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1032 m_text
->PushEventHandler(m_textEvtHandler
);
1037 wxComboCtrlBase::CreateTextCtrl(int style
)
1039 if ( !(m_windowStyle
& wxCB_READONLY
) )
1044 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1045 // not used by the wxPropertyGrid and therefore the tab is processed by
1046 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1047 // navigation event is then sent to the wrong window.
1048 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1050 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1051 style
|= wxTE_PROCESS_ENTER
;
1053 // Ignore EVT_TEXT generated by the constructor (but only
1054 // if the event redirector already exists)
1055 // NB: This must be " = 1" instead of "++";
1056 if ( m_textEvtHandler
)
1057 m_ignoreEvtText
= 1;
1059 m_ignoreEvtText
= 0;
1061 m_text
= new wxComboCtrlTextCtrl();
1062 m_text
->Create(this, wxID_ANY
, m_valueString
,
1063 wxDefaultPosition
, wxSize(10,-1),
1065 m_text
->SetHint(m_hintText
);
1069 void wxComboCtrlBase::OnThemeChange()
1071 // Leave the default bg on the Mac so the area used by the focus ring will
1072 // be the correct colour and themed brush. Instead we'll use
1073 // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
1075 #if defined(__WXMSW__) || defined(__WXGTK__)
1076 wxVisualAttributes vattrs
= wxComboBox::GetClassDefaultAttributes();
1078 wxVisualAttributes vattrs
;
1079 vattrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1080 vattrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1083 // Only change the colours if application has not specified
1087 SetOwnForegroundColour(vattrs
.colFg
);
1092 SetOwnBackgroundColour(vattrs
.colBg
);
1095 #endif // !__WXMAC__
1098 wxComboCtrlBase::~wxComboCtrlBase()
1103 #if INSTALL_TOPLEV_HANDLER
1104 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1105 m_toplevEvtHandler
= NULL
;
1111 m_text
->RemoveEventHandler(m_textEvtHandler
);
1113 delete m_textEvtHandler
;
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1121 // Recalculates button and textctrl areas
1122 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
1124 wxSize sz
= GetClientSize();
1125 int customBorder
= m_widthCustomBorder
;
1126 int btnBorder
; // border for button only
1128 // check if button should really be outside the border: we'll do it it if
1129 // its platform default or bitmap+pushbutton background is used, but not if
1130 // there is vertical size adjustment or horizontal spacing.
1131 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1132 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
1133 m_btnSpacingX
== 0 &&
1136 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1139 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1140 m_btnSpacingX
== 0 && !m_bmpNormal
.Ok() )
1142 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1147 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1148 btnBorder
= customBorder
;
1151 // Defaul indentation
1152 if ( m_marginLeft
< 0 )
1153 m_marginLeft
= GetNativeTextIndent();
1155 int butWidth
= btnWidth
;
1157 if ( butWidth
<= 0 )
1158 butWidth
= m_btnWidDefault
;
1160 m_btnWidDefault
= butWidth
;
1162 if ( butWidth
<= 0 )
1165 int butHeight
= sz
.y
- btnBorder
*2;
1167 // Adjust button width
1169 butWidth
= m_btnWid
;
1172 // Adjust button width to match aspect ratio
1173 // (but only if control is smaller than best size).
1174 int bestHeight
= GetBestSize().y
;
1175 int height
= GetSize().y
;
1177 if ( height
< bestHeight
)
1179 // Make very small buttons square, as it makes
1180 // them accommodate arrow image better and still
1183 butWidth
= (height
*butWidth
)/bestHeight
;
1185 butWidth
= butHeight
;
1189 // Adjust button height
1191 butHeight
= m_btnHei
;
1193 // Use size of normal bitmap if...
1196 // button width is set to default and blank button bg is not drawn
1197 if ( m_bmpNormal
.Ok() )
1199 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1200 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1202 // If drawing blank button background, we need to add some margin.
1203 if ( m_blankButtonBg
)
1205 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1206 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1209 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1210 butWidth
= bmpReqWidth
;
1211 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1212 butHeight
= bmpReqHeight
;
1214 // Need to fix height?
1215 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1217 int newY
= butHeight
+(customBorder
*2);
1218 SetClientSize(wxDefaultCoord
,newY
);
1219 if ( m_bmpNormal
.Ok() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1220 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1222 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1228 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1230 m_btnSize
.x
= butWidth
;
1231 m_btnSize
.y
= butHeight
;
1233 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1234 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1235 m_btnArea
.width
= butAreaWid
;
1236 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1238 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1239 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1240 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1241 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1246 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1247 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1252 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1257 wxSize sz
= GetClientSize();
1259 int customBorder
= m_widthCustomBorder
;
1260 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1264 if ( !m_widthCustomPaint
)
1266 // No special custom paint area - we can use 0 left margin
1268 if ( m_text
->SetMargins(0) )
1269 textCtrlXAdjust
= 0;
1270 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1274 // There is special custom paint area - it is better to
1275 // use some margin with the wxTextCtrl.
1276 m_text
->SetMargins(m_marginLeft
);
1277 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1278 m_marginLeft
+ textCtrlXAdjust
;
1281 // Centre textctrl vertically, if needed
1282 #if !TEXTCTRL_TEXT_CENTERED
1283 int tcSizeY
= m_text
->GetBestSize().y
;
1284 int diff0
= sz
.y
- tcSizeY
;
1285 int y
= textCtrlYAdjust
+ (diff0
/2);
1287 wxUnusedVar(textCtrlYAdjust
);
1291 if ( y
< customBorder
)
1296 m_tcArea
.width
- m_tcArea
.x
- x
,
1299 // Make sure textctrl doesn't exceed the bottom custom border
1300 wxSize tsz
= m_text
->GetSize();
1301 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1304 tsz
.y
= tsz
.y
- diff1
- 1;
1305 m_text
->SetSize(tsz
);
1310 // If it has border, have textctrl fill the entire text field.
1311 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1313 m_tcArea
.width
- m_widthCustomPaint
,
1318 wxSize
wxComboCtrlBase::DoGetBestSize() const
1320 wxSize
sizeText(150,0);
1323 sizeText
= m_text
->GetBestSize();
1325 // TODO: Better method to calculate close-to-native control height.
1329 fhei
= (m_font
.GetPointSize()*2) + 5;
1330 else if ( wxNORMAL_FONT
->Ok() )
1331 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1333 fhei
= sizeText
.y
+ 4;
1335 // Need to force height to accomodate bitmap?
1336 int btnSizeY
= m_btnSize
.y
;
1337 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1340 // Control height doesn't depend on border
1343 int border = m_windowStyle & wxBORDER_MASK;
1344 if ( border == wxSIMPLE_BORDER )
1346 else if ( border == wxNO_BORDER )
1347 fhei += (m_widthCustomBorder*2);
1353 // Final adjustments
1359 // these are the numbers from the HIG:
1360 switch ( m_windowVariant
)
1362 case wxWINDOW_VARIANT_NORMAL
:
1366 case wxWINDOW_VARIANT_SMALL
:
1369 case wxWINDOW_VARIANT_MINI
:
1375 fhei
+= 2 * FOCUS_RING
;
1376 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1378 wxSize
ret(width
, fhei
);
1383 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1388 // defined by actual wxComboCtrls
1394 // ----------------------------------------------------------------------------
1395 // standard operations
1396 // ----------------------------------------------------------------------------
1398 bool wxComboCtrlBase::Enable(bool enable
)
1400 if ( !wxControl::Enable(enable
) )
1404 m_btn
->Enable(enable
);
1406 m_text
->Enable(enable
);
1413 bool wxComboCtrlBase::Show(bool show
)
1415 if ( !wxControl::Show(show
) )
1427 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1429 if ( !wxControl::SetFont(font
) )
1434 // Without hiding the wxTextCtrl there would be some
1435 // visible 'flicker' (at least on Windows XP).
1437 m_text
->SetFont(font
);
1446 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1448 wxControl::DoSetToolTip(tooltip
);
1450 // Set tool tip for button and text box
1453 const wxString
&tip
= tooltip
->GetTip();
1454 if ( m_text
) m_text
->SetToolTip(tip
);
1455 if ( m_btn
) m_btn
->SetToolTip(tip
);
1459 if ( m_text
) m_text
->SetToolTip( NULL
);
1460 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1463 #endif // wxUSE_TOOLTIPS
1465 bool wxComboCtrlBase::SetForegroundColour(const wxColour
& colour
)
1467 if ( wxControl::SetForegroundColour(colour
) )
1470 m_text
->SetForegroundColour(colour
);
1476 bool wxComboCtrlBase::SetBackgroundColour(const wxColour
& colour
)
1478 if ( wxControl::SetBackgroundColour(colour
) )
1481 m_text
->SetBackgroundColour(colour
);
1486 // ----------------------------------------------------------------------------
1488 // ----------------------------------------------------------------------------
1490 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1491 // prepare combo box background on area in a way typical on platform
1492 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1494 wxSize sz
= GetClientSize();
1496 bool doDrawFocusRect
; // also selected
1498 // For smaller size control (and for disabled background) use less spacing
1502 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1505 isEnabled
= IsEnabled();
1506 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1508 // Windows-style: for smaller size control (and for disabled background) use less spacing
1509 focusSpacingX
= isEnabled
? 2 : 1;
1510 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1514 // Drawing a list item
1515 isEnabled
= true; // they are never disabled
1516 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1522 // Set the background sub-rectangle for selection, disabled etc
1523 wxRect
selRect(rect
);
1524 selRect
.y
+= focusSpacingY
;
1525 selRect
.height
-= (focusSpacingY
*2);
1529 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1530 wcp
+= m_widthCustomPaint
;
1532 selRect
.x
+= wcp
+ focusSpacingX
;
1533 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1538 bool doDrawSelRect
= true;
1540 // Determine foreground colour
1543 if ( doDrawFocusRect
)
1545 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1547 else if ( m_hasFgCol
)
1549 // Honour the custom foreground colour
1550 fgCol
= GetForegroundColour();
1554 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1559 fgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1562 // Determine background colour
1565 if ( doDrawFocusRect
)
1567 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1569 else if ( m_hasBgCol
)
1571 // Honour the custom background colour
1572 bgCol
= GetBackgroundColour();
1576 #ifndef __WXMAC__ // see note in OnThemeChange
1577 doDrawSelRect
= false;
1578 bgCol
= GetBackgroundColour();
1580 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1586 #ifndef __WXMAC__ // see note in OnThemeChange
1587 bgCol
= GetBackgroundColour();
1589 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1593 dc
.SetTextForeground( fgCol
);
1594 dc
.SetBrush( bgCol
);
1595 if ( doDrawSelRect
)
1598 dc
.DrawRectangle( selRect
);
1601 // Don't clip exactly to the selection rectangle so we can draw
1602 // to the non-selected area in front of it.
1603 wxRect
clipRect(rect
.x
,rect
.y
,
1604 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1605 dc
.SetClippingRegion(clipRect
);
1608 // Save the library size a bit for platforms that re-implement this.
1609 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1614 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1616 int drawState
= m_btnState
;
1618 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1619 GetPopupWindowState() >= Animating
)
1620 drawState
|= wxCONTROL_PRESSED
;
1622 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1623 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1627 // Make sure area is not larger than the control
1628 if ( drawRect
.y
< rect
.y
)
1629 drawRect
.y
= rect
.y
;
1630 if ( drawRect
.height
> rect
.height
)
1631 drawRect
.height
= rect
.height
;
1633 bool enabled
= IsEnabled();
1636 drawState
|= wxCONTROL_DISABLED
;
1638 if ( !m_bmpNormal
.Ok() )
1640 if ( flags
& Button_BitmapOnly
)
1643 // Need to clear button background even if m_btn is present
1644 if ( flags
& Button_PaintBackground
)
1648 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1649 bgCol
= GetParent()->GetBackgroundColour();
1651 bgCol
= GetBackgroundColour();
1655 dc
.DrawRectangle(rect
);
1658 // Draw standard button
1659 wxRendererNative::Get().DrawComboBoxDropButton(this,
1671 pBmp
= &m_bmpDisabled
;
1672 else if ( m_btnState
& wxCONTROL_PRESSED
)
1673 pBmp
= &m_bmpPressed
;
1674 else if ( m_btnState
& wxCONTROL_CURRENT
)
1677 pBmp
= &m_bmpNormal
;
1679 if ( m_blankButtonBg
)
1681 // If using blank button background, we need to clear its background
1682 // with button face colour instead of colour for rest of the control.
1683 if ( flags
& Button_PaintBackground
)
1685 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1686 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1689 dc
.DrawRectangle(rect
);
1692 if ( !(flags
& Button_BitmapOnly
) )
1694 wxRendererNative::Get().DrawPushButton(this,
1703 // Need to clear button background even if m_btn is present
1704 // (assume non-button background was cleared just before this call so brushes are good)
1705 if ( flags
& Button_PaintBackground
)
1706 dc
.DrawRectangle(rect
);
1709 // Draw bitmap centered in drawRect
1710 dc
.DrawBitmap(*pBmp
,
1711 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1712 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1717 void wxComboCtrlBase::RecalcAndRefresh()
1721 wxSizeEvent
evt(GetSize(),GetId());
1722 GetEventHandler()->ProcessEvent(evt
);
1727 // ----------------------------------------------------------------------------
1728 // miscellaneous event handlers
1729 // ----------------------------------------------------------------------------
1731 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1733 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1735 if ( m_ignoreEvtText
> 0 )
1742 // Change event id, object and string before relaying it forward
1743 event
.SetId(GetId());
1744 wxString s
= event
.GetString();
1745 event
.SetEventObject(this);
1750 // call if cursor is on button area or mouse is captured for the button
1751 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1754 int type
= event
.GetEventType();
1756 if ( type
== wxEVT_MOTION
)
1758 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1759 IsPopupWindowState(Hidden
) )
1761 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1763 // Mouse hover begins
1764 m_btnState
|= wxCONTROL_CURRENT
;
1765 if ( HasCapture() ) // Retain pressed state.
1766 m_btnState
|= wxCONTROL_PRESSED
;
1770 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1773 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1777 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1779 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1781 m_btnState
|= wxCONTROL_PRESSED
;
1784 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1787 // If showing popup now, do not capture mouse or there will be interference
1791 else if ( type
== wxEVT_LEFT_UP
)
1794 // Only accept event if mouse was left-press was previously accepted
1798 if ( m_btnState
& wxCONTROL_PRESSED
)
1800 // If mouse was inside, fire the click event.
1801 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1803 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1807 m_btnState
&= ~(wxCONTROL_PRESSED
);
1811 else if ( type
== wxEVT_LEAVE_WINDOW
)
1813 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1815 m_btnState
&= ~(wxCONTROL_CURRENT
);
1818 if ( IsPopupWindowState(Hidden
) )
1820 m_btnState
&= ~(wxCONTROL_PRESSED
);
1828 // Never have 'hot' state when popup is being shown
1829 // (this is mostly needed because of the animation).
1830 if ( !IsPopupWindowState(Hidden
) )
1831 m_btnState
&= ~wxCONTROL_CURRENT
;
1836 // returns true if event was consumed or filtered
1837 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1838 int WXUNUSED(flags
) )
1840 wxLongLong t
= ::wxGetLocalTimeMillis();
1841 int evtType
= event
.GetEventType();
1843 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1844 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1846 if ( IsPopupWindowState(Visible
) &&
1847 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1855 // Filter out clicks on button immediately after popup dismiss
1856 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1858 event
.SetEventType(0);
1865 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1867 int evtType
= event
.GetEventType();
1869 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1870 (m_windowStyle
& wxCB_READONLY
) )
1872 if ( GetPopupWindowState() >= Animating
)
1874 #if USES_WXPOPUPWINDOW
1875 // Click here always hides the popup.
1876 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1882 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1884 // In read-only mode, clicking the text is the
1885 // same as clicking the button.
1888 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1890 //if ( m_popupInterface->CycleValue() )
1892 if ( m_popupInterface
)
1893 m_popupInterface
->OnComboDoubleClick();
1897 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1899 if ( IsPopupShown() )
1901 // relay (some) mouse events to the popup
1902 m_popup
->GetEventHandler()->ProcessEvent(event
);
1904 else if ( event
.GetWheelAxis() == 0 &&
1905 event
.GetWheelRotation() != 0 &&
1906 event
.GetModifiers() == 0 )
1908 // Translate mousewheel actions into key up/down. This is
1909 // the simplest way of getting native behaviour: scrolling the
1910 // wheel moves selection up/down by one item.
1911 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1912 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1915 GetEventHandler()->ProcessEvent(kevent
);
1928 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1930 if ( IsPopupShown() )
1932 // pass it to the popped up control
1933 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1937 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1939 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1941 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1945 if ( IsKeyPopupToggle(event
) )
1951 int comboStyle
= GetWindowStyle();
1952 wxComboPopup
* popupInterface
= GetPopupControl();
1954 if ( !popupInterface
)
1960 int keycode
= event
.GetKeyCode();
1962 if ( (comboStyle
& wxCB_READONLY
) ||
1963 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1965 popupInterface
->OnComboKeyEvent(event
);
1972 void wxComboCtrlBase::OnCharEvent(wxKeyEvent
& event
)
1974 if ( IsPopupShown() )
1976 // pass it to the popped up control
1977 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1981 wxComboPopup
* popupInterface
= GetPopupControl();
1982 if ( popupInterface
)
1984 popupInterface
->OnComboCharEvent(event
);
1993 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1995 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1997 wxWindow
* tc
= GetTextCtrl();
1998 if ( tc
&& tc
!= DoFindFocus() )
2007 void wxComboCtrlBase::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2011 m_resetFocus
= false;
2012 wxWindow
* tc
= GetTextCtrl();
2018 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2021 // left margin may also have changed
2022 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2023 m_marginLeft
= GetNativeTextIndent();
2027 // ----------------------------------------------------------------------------
2029 // ----------------------------------------------------------------------------
2031 // Create popup window and the child control
2032 void wxComboCtrlBase::CreatePopup()
2034 wxComboPopup
* popupInterface
= m_popupInterface
;
2039 #ifdef wxComboPopupWindowBase2
2040 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2042 #if !USES_GENERICTLW
2043 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2045 int tlwFlags
= wxNO_BORDER
;
2046 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2047 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2050 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2051 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2052 wxPoint(-21,-21), wxSize(20, 20),
2055 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2056 wxPoint(-21,-21), wxSize(20, 20),
2060 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2063 #endif // wxComboPopupWindowBase2
2065 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2066 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2068 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2069 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2072 popupInterface
->Create(m_winPopup
);
2073 m_popup
= popup
= popupInterface
->GetControl();
2075 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2076 popup
->PushEventHandler( m_popupEvtHandler
);
2078 // This may be helpful on some platforms
2079 // (eg. it bypasses a wxGTK popupwindow bug where
2080 // window is not initially hidden when it should be)
2083 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2086 // Destroy popup window and the child control
2087 void wxComboCtrlBase::DestroyPopup()
2092 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2094 wxDELETE(m_popupEvtHandler
);
2096 wxDELETE(m_popupInterface
);
2100 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2101 wxDELETE(m_popupWinEvtHandler
);
2102 m_winPopup
->Destroy();
2109 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
2111 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2115 iface
->InitBase(this);
2118 m_popupInterface
= iface
;
2120 if ( !iface
->LazyCreate() )
2129 // This must be done after creation
2130 if ( m_valueString
.length() )
2132 iface
->SetStringValue(m_valueString
);
2137 // Ensures there is atleast the default popup
2138 void wxComboCtrlBase::EnsurePopupControl()
2140 if ( !m_popupInterface
)
2141 SetPopupControl(NULL
);
2144 void wxComboCtrlBase::OnButtonClick()
2146 // Derived classes can override this method for totally custom
2148 switch ( GetPopupWindowState() )
2165 void wxComboCtrlBase::Popup()
2167 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2168 event
.SetEventObject(this);
2169 HandleWindowEvent(event
);
2174 void wxComboCtrlBase::ShowPopup()
2176 EnsurePopupControl();
2177 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2179 if ( IsPopupWindowState(Animating
) )
2184 // Space above and below
2190 wxSize ctrlSz
= GetSize();
2192 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
2193 scrPos
= GetParent()->ClientToScreen(GetPosition());
2195 spaceAbove
= scrPos
.y
;
2196 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2198 maxHeightPopup
= spaceBelow
;
2199 if ( spaceAbove
> spaceBelow
)
2200 maxHeightPopup
= spaceAbove
;
2203 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2205 if ( widthPopup
< m_widthMinPopup
)
2206 widthPopup
= m_widthMinPopup
;
2208 wxWindow
* winPopup
= m_winPopup
;
2211 // Need to disable tab traversal of parent
2213 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2214 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2215 // that if transient popup is open, then tab traversal is to be ignored.
2216 // However, I think this code would still be needed for cases where
2217 // transient popup doesn't work yet (wxWinCE?).
2218 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2219 wxWindow
* parent
= mainCtrl
->GetParent();
2220 int parentFlags
= parent
->GetWindowStyle();
2221 if ( parentFlags
& wxTAB_TRAVERSAL
)
2223 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2224 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2230 winPopup
= m_winPopup
;
2240 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2242 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2243 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2246 popup
->SetSize(adjustedSize
);
2248 m_popupInterface
->OnPopup();
2251 // Reposition and resize popup window
2254 wxSize szp
= popup
->GetSize();
2257 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2259 // Default anchor is wxLEFT
2260 int anchorSide
= m_anchorSide
;
2262 anchorSide
= wxLEFT
;
2264 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2265 int leftX
= scrPos
.x
- m_extLeft
;
2267 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2270 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
2272 // If there is not enough horizontal space, anchor on the other side.
2273 // If there is no space even then, place the popup at x 0.
2274 if ( anchorSide
== wxRIGHT
)
2278 if ( (leftX
+szp
.x
) < screenWidth
)
2279 anchorSide
= wxLEFT
;
2286 if ( (leftX
+szp
.x
) >= screenWidth
)
2289 anchorSide
= wxRIGHT
;
2295 // Select x coordinate according to the anchor side
2296 if ( anchorSide
== wxRIGHT
)
2298 else if ( anchorSide
== wxLEFT
)
2303 int showFlags
= CanDeferShow
;
2305 if ( spaceBelow
< szp
.y
)
2307 popupY
= scrPos
.y
- szp
.y
;
2308 showFlags
|= ShowAbove
;
2311 #if INSTALL_TOPLEV_HANDLER
2312 // Put top level window event handler into place
2313 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2315 if ( !m_toplevEvtHandler
)
2316 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2318 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2320 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2321 toplev
->PushEventHandler( m_toplevEvtHandler
);
2325 // Set string selection (must be this way instead of SetStringSelection)
2328 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2329 m_text
->SelectAll();
2331 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2335 // This is neede since focus/selection indication may change when popup is shown
2339 // This must be after SetStringValue
2340 m_popupWinState
= Animating
;
2342 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2345 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2346 AnimateShow( popupWinRect
, showFlags
) )
2348 DoShowPopup( popupWinRect
, showFlags
);
2352 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2357 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2359 wxWindow
* winPopup
= m_winPopup
;
2361 if ( IsPopupWindowState(Animating
) )
2363 // Make sure the popup window is shown in the right position.
2364 // Should not matter even if animation already did this.
2366 // Some platforms (GTK) may like SetSize and Move to be separate
2367 // (though the bug was probably fixed).
2368 winPopup
->SetSize( rect
);
2370 #if USES_WXPOPUPTRANSIENTWINDOW
2371 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2372 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2377 m_popupWinState
= Visible
;
2379 // If popup window was a generic top-level window, or the
2380 // wxPopupWindow implemenation on this platform is classified as
2381 // perfect, then we should be able to safely set focus to the popup
2383 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2384 m_popup
->SetFocus();
2386 else if ( IsPopupWindowState(Hidden
) )
2388 // Animation was aborted
2390 wxASSERT( !winPopup
->IsShown() );
2392 m_popupWinState
= Hidden
;
2398 void wxComboCtrlBase::OnPopupDismiss(bool generateEvent
)
2400 // Just in case, avoid double dismiss
2401 if ( IsPopupWindowState(Hidden
) )
2404 // This must be set before focus - otherwise there will be recursive
2405 // OnPopupDismisses.
2406 m_popupWinState
= Hidden
;
2409 m_winPopup
->Disable();
2411 // Inform popup control itself
2412 m_popupInterface
->OnDismiss();
2414 if ( m_popupEvtHandler
)
2415 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2417 #if INSTALL_TOPLEV_HANDLER
2418 // Remove top level window event handler
2419 if ( m_toplevEvtHandler
)
2421 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2423 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2427 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2429 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2430 m_timeCanAcceptClick
+= 150;
2432 // If cursor not on dropdown button, then clear its state
2433 // (technically not required by all ports, but do it for all just in case)
2434 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2437 // Return parent's tab traversal flag.
2438 // See ShowPopup for notes.
2439 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2441 wxWindow
* parent
= GetParent();
2442 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2443 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2446 // refresh control (necessary even if m_text)
2451 if ( generateEvent
)
2453 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2454 event
.SetEventObject(this);
2455 HandleWindowEvent(event
);
2459 void wxComboCtrlBase::HidePopup(bool generateEvent
)
2461 // Should be able to call this without popup interface
2462 if ( IsPopupWindowState(Hidden
) )
2465 // transfer value and show it in textctrl, if any
2466 if ( !IsPopupWindowState(Animating
) )
2467 SetValueByUser( m_popupInterface
->GetStringValue() );
2471 OnPopupDismiss(generateEvent
);
2474 // ----------------------------------------------------------------------------
2475 // customization methods
2476 // ----------------------------------------------------------------------------
2478 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2479 int side
, int spacingX
)
2484 m_btnSpacingX
= spacingX
;
2486 if ( width
> 0 || height
> 0 || spacingX
)
2487 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2492 wxSize
wxComboCtrlBase::GetButtonSize()
2494 if ( m_btnSize
.x
> 0 )
2497 wxSize
retSize(m_btnWid
,m_btnHei
);
2499 // Need to call CalculateAreas now if button size is
2500 // is not explicitly specified.
2501 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2505 retSize
= m_btnSize
;
2511 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2513 const wxBitmap
& bmpPressed
,
2514 const wxBitmap
& bmpHover
,
2515 const wxBitmap
& bmpDisabled
)
2517 m_bmpNormal
= bmpNormal
;
2518 m_blankButtonBg
= blankButtonBg
;
2520 if ( bmpPressed
.Ok() )
2521 m_bmpPressed
= bmpPressed
;
2523 m_bmpPressed
= bmpNormal
;
2525 if ( bmpHover
.Ok() )
2526 m_bmpHover
= bmpHover
;
2528 m_bmpHover
= bmpNormal
;
2530 if ( bmpDisabled
.Ok() )
2531 m_bmpDisabled
= bmpDisabled
;
2533 m_bmpDisabled
= bmpNormal
;
2538 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2542 // move textctrl accordingly
2543 wxRect r
= m_text
->GetRect();
2544 int inc
= width
- m_widthCustomPaint
;
2547 m_text
->SetSize( r
);
2550 m_widthCustomPaint
= width
;
2555 bool wxComboCtrlBase::DoSetMargins(const wxPoint
& margins
)
2557 // For general sanity's sake, we ignore top margin. Instead
2558 // we will always try to center the text vertically.
2561 if ( margins
.x
!= -1 )
2563 m_marginLeft
= margins
.x
;
2564 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2568 m_marginLeft
= GetNativeTextIndent();
2569 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2572 if ( margins
.y
!= -1 )
2582 wxPoint
wxComboCtrlBase::DoGetMargins() const
2584 return wxPoint(m_marginLeft
, -1);
2587 #if WXWIN_COMPATIBILITY_2_8
2588 void wxComboCtrlBase::SetTextIndent( int indent
)
2592 m_marginLeft
= GetNativeTextIndent();
2593 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2597 m_marginLeft
= indent
;
2598 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2604 wxCoord
wxComboCtrlBase::GetTextIndent() const
2606 return m_marginLeft
;
2610 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2612 return DEFAULT_TEXT_INDENT
;
2615 void wxComboCtrlBase::SetTextCtrlStyle( int style
)
2617 m_textCtrlStyle
= style
;
2620 m_text
->SetWindowStyle(style
);
2623 // ----------------------------------------------------------------------------
2624 // wxTextEntry interface
2625 // ----------------------------------------------------------------------------
2627 wxString
wxComboCtrlBase::DoGetValue() const
2630 return m_text
->GetValue();
2631 return m_valueString
;
2634 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
,
2637 DoSetValue(value
, withEvent
? SetValue_SendEvent
: 0);
2640 void wxComboCtrlBase::OnSetValue(const wxString
& value
)
2642 // Note: before wxComboCtrl inherited from wxTextEntry,
2643 // this code used to be in SetValueWithEvent().
2645 // Since wxComboPopup may want to paint the combo as well, we need
2646 // to set the string value here (as well as sometimes in ShowPopup).
2647 if ( m_valueString
!= value
)
2650 wxString trueValue
= value
;
2652 // Conform to wxComboBox behavior: read-only control can only accept
2653 // valid list items and empty string
2654 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2656 found
= m_popupInterface
->FindItem(value
,
2662 m_valueString
= trueValue
;
2664 EnsurePopupControl();
2666 if ( m_popupInterface
)
2667 m_popupInterface
->SetStringValue(trueValue
);
2674 void wxComboCtrlBase::SetValueByUser(const wxString
& value
)
2676 // NB: Order of function calls is important here. Otherwise
2677 // the SelectAll() may not work.
2681 m_text
->SetValue(value
);
2683 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2684 m_text
->SelectAll();
2690 // In this SetValue variant wxComboPopup::SetStringValue is not called
2691 void wxComboCtrlBase::SetText(const wxString
& value
)
2693 // Unlike in SetValue(), this must be called here or
2694 // the behaviour will no be consistent in readonlys.
2695 EnsurePopupControl();
2697 m_valueString
= value
;
2702 m_text
->SetValue( value
);
2708 void wxComboCtrlBase::Copy()
2714 void wxComboCtrlBase::Cut()
2720 void wxComboCtrlBase::Paste()
2726 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2729 m_text
->SetInsertionPoint(pos
);
2732 long wxComboCtrlBase::GetInsertionPoint() const
2735 return m_text
->GetInsertionPoint();
2740 long wxComboCtrlBase::GetLastPosition() const
2743 return m_text
->GetLastPosition();
2748 void wxComboCtrlBase::WriteText(const wxString
& text
)
2752 m_text
->WriteText(text
);
2753 OnSetValue(m_text
->GetValue());
2761 void wxComboCtrlBase::DoSetValue(const wxString
& value
, int flags
)
2765 if ( flags
& SetValue_SendEvent
)
2766 m_text
->SetValue(value
);
2768 m_text
->ChangeValue(value
);
2774 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2778 m_text
->Replace(from
, to
, value
);
2779 OnSetValue(m_text
->GetValue());
2783 void wxComboCtrlBase::Remove(long from
, long to
)
2787 m_text
->Remove(from
, to
);
2788 OnSetValue(m_text
->GetValue());
2792 void wxComboCtrlBase::SetSelection(long from
, long to
)
2795 m_text
->SetSelection(from
, to
);
2798 void wxComboCtrlBase::GetSelection(long *from
, long *to
) const
2802 m_text
->GetSelection(from
, to
);
2811 bool wxComboCtrlBase::IsEditable() const
2814 return m_text
->IsEditable();
2818 void wxComboCtrlBase::SetEditable(bool editable
)
2821 m_text
->SetEditable(editable
);
2824 void wxComboCtrlBase::Undo()
2830 void wxComboCtrlBase::Redo()
2836 bool wxComboCtrlBase::CanUndo() const
2839 return m_text
->CanUndo();
2844 bool wxComboCtrlBase::CanRedo() const
2847 return m_text
->CanRedo();
2852 bool wxComboCtrlBase::SetHint(const wxString
& hint
)
2857 res
= m_text
->SetHint(hint
);
2862 wxString
wxComboCtrlBase::GetHint() const
2867 #endif // wxUSE_COMBOCTRL