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 succesfully 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 // ----------------------------------------------------------------------------
679 // ----------------------------------------------------------------------------
682 // This is pushed to the event handler queue of the child textctrl.
684 class wxComboBoxExtraInputHandler
: public wxEvtHandler
688 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
693 virtual ~wxComboBoxExtraInputHandler() { }
694 void OnKey(wxKeyEvent
& event
);
695 void OnFocus(wxFocusEvent
& event
);
698 wxComboCtrlBase
* m_combo
;
701 DECLARE_EVENT_TABLE()
705 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
706 EVT_KEY_DOWN(wxComboBoxExtraInputHandler
::OnKey
)
707 EVT_KEY_UP(wxComboBoxExtraInputHandler
::OnKey
)
708 EVT_CHAR(wxComboBoxExtraInputHandler
::OnKey
)
709 EVT_SET_FOCUS(wxComboBoxExtraInputHandler
::OnFocus
)
710 EVT_KILL_FOCUS(wxComboBoxExtraInputHandler
::OnFocus
)
714 void wxComboBoxExtraInputHandler
::OnKey(wxKeyEvent
& event
)
716 // Let the wxComboCtrl event handler have a go first.
717 wxComboCtrlBase
* combo
= m_combo
;
719 wxKeyEvent
redirectedEvent(event
);
720 redirectedEvent
.SetId(combo
->GetId());
721 redirectedEvent
.SetEventObject(combo
);
723 if ( !combo
->GetEventHandler()->ProcessEvent(redirectedEvent
) )
725 // Don't let TAB through to the text ctrl - looks ugly
726 if ( event
.GetKeyCode() != WXK_TAB
)
731 void wxComboBoxExtraInputHandler
::OnFocus(wxFocusEvent
& event
)
733 // FIXME: This code does run when control is clicked,
734 // yet on Windows it doesn't select all the text.
735 if ( event
.GetEventType() == wxEVT_SET_FOCUS
&&
736 !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
738 if ( m_combo
->GetTextCtrl() )
739 m_combo
->GetTextCtrl()->SelectAll();
741 m_combo
->SetSelection(-1,-1);
744 // Send focus indication to parent.
745 // NB: This is needed for cases where the textctrl gets focus
746 // instead of its parent. While this may trigger multiple
747 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
748 // from combo's focus event handler), they should be quite
750 wxFocusEvent
evt2(event
);
751 evt2
.SetId(m_combo
->GetId());
752 evt2
.SetEventObject(m_combo
);
753 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
760 // This is pushed to the event handler queue of the control in popup.
763 class wxComboPopupEvtHandler
: public wxEvtHandler
767 wxComboPopupEvtHandler( wxComboCtrlBase
* combo
)
771 m_beenInside
= false;
773 // Let's make it so that the popup control will not receive mouse
774 // events until mouse left button has been up.
775 m_blockEventsToPopup
= true;
777 virtual ~wxComboPopupEvtHandler() { }
779 void OnMouseEvent( wxMouseEvent
& event
);
781 // Called from wxComboCtrlBase::OnPopupDismiss
782 void OnPopupDismiss()
784 m_beenInside
= false;
785 m_blockEventsToPopup
= true;
789 wxComboCtrlBase
* m_combo
;
792 bool m_blockEventsToPopup
;
795 DECLARE_EVENT_TABLE()
799 BEGIN_EVENT_TABLE(wxComboPopupEvtHandler
, wxEvtHandler
)
800 EVT_MOUSE_EVENTS(wxComboPopupEvtHandler
::OnMouseEvent
)
804 void wxComboPopupEvtHandler
::OnMouseEvent( wxMouseEvent
& event
)
806 wxPoint pt
= event
.GetPosition();
807 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
808 int evtType
= event
.GetEventType();
809 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
810 bool relayToButton
= false;
814 if ( !isInside
|| !m_combo
->IsPopupShown() )
816 // Mouse is outside the popup or popup is not actually shown (yet)
818 if ( evtType
== wxEVT_MOTION
||
819 evtType
== wxEVT_LEFT_DOWN
||
820 evtType
== wxEVT_LEFT_UP
||
821 evtType
== wxEVT_RIGHT_DOWN
)
823 // Block motion and click events outside the popup
829 // Mouse is inside the popup, which is fully shown
833 // Do not let the popup control respond to mouse events until
834 // mouse press used to display the popup has been lifted. This
835 // is important for users with slower mouse fingers or mouse
836 // drivers. Note that we have some redundancy here, just in
837 // case the popup is some native control that does not emit all
838 // mouse event types.
839 if ( evtType
== wxEVT_MOTION
)
841 if ( m_blockEventsToPopup
)
843 if ( event
.LeftIsDown() )
846 m_blockEventsToPopup
= false;
849 else if ( evtType
== wxEVT_LEFT_DOWN
)
851 if ( m_blockEventsToPopup
)
852 m_blockEventsToPopup
= false;
854 else if ( evtType
== wxEVT_LEFT_UP
)
856 if ( m_blockEventsToPopup
)
858 // On first left up, stop blocking mouse events (but still
860 m_blockEventsToPopup
= false;
863 // Also, this button press was (probably) used to display
864 // the popup, so relay it back to the drop-down button
865 // (which supposedly originated it). This is necessary to
866 // refresh it properly.
867 relayToButton
= true;
870 else if ( m_blockEventsToPopup
)
877 // Some mouse events to popup that happen outside it, before cursor
878 // has been inside the popup, need to be ignored by it but relayed to
881 if ( evtType
== wxEVT_LEFT_UP
)
883 if ( !m_combo
->IsPopupShown() )
886 relayToButton
= true;
888 else if ( !isInside
&& !m_beenInside
)
890 // Popup is shown but the cursor is not inside, nor it has been
891 relayToButton
= true;
897 wxWindow
* btn
= m_combo
->GetButton();
899 btn
->GetEventHandler()->ProcessEvent(event
);
901 // Bypass the event handling mechanism. Using it would be
902 // confusing for the platform-specific wxComboCtrl
904 m_combo
->HandleButtonMouseEvent(event
, 0);
908 // ----------------------------------------------------------------------------
909 // wxComboCtrlTextCtrl
910 // ----------------------------------------------------------------------------
912 class wxComboCtrlTextCtrl
: public wxTextCtrl
915 wxComboCtrlTextCtrl() : wxTextCtrl() { }
916 virtual ~wxComboCtrlTextCtrl() { }
918 virtual wxWindow
*GetMainWindowOfCompositeControl()
920 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
922 // Returning this instead of just 'parent' lets FindFocus work
923 // correctly even when parent control is a child of a composite
924 // generic control (as is case with wxGenericDatePickerCtrl).
925 return combo
->GetMainWindowOfCompositeControl();
929 // ----------------------------------------------------------------------------
931 // ----------------------------------------------------------------------------
934 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
935 EVT_TEXT(wxID_ANY
,wxComboCtrlBase
::OnTextCtrlEvent
)
936 EVT_SIZE(wxComboCtrlBase
::OnSizeEvent
)
937 EVT_SET_FOCUS(wxComboCtrlBase
::OnFocusEvent
)
938 EVT_KILL_FOCUS(wxComboCtrlBase
::OnFocusEvent
)
939 EVT_IDLE(wxComboCtrlBase
::OnIdleEvent
)
940 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
941 EVT_KEY_DOWN(wxComboCtrlBase
::OnKeyEvent
)
942 EVT_CHAR(wxComboCtrlBase
::OnCharEvent
)
943 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase
::OnTextCtrlEvent
)
944 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase
::OnSysColourChanged
)
948 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
950 void wxComboCtrlBase
::Init()
954 m_popupWinState
= Hidden
;
957 m_popupInterface
= NULL
;
959 m_popupEvtHandler
= NULL
;
960 m_textEvtHandler
= NULL
;
962 #if INSTALL_TOPLEV_HANDLER
963 m_toplevEvtHandler
= NULL
;
966 m_mainCtrlWnd
= this;
969 m_widthMinPopup
= -1;
971 m_widthCustomPaint
= 0;
972 m_widthCustomBorder
= 0;
976 m_blankButtonBg
= false;
978 m_popupWinType
= POPUPWIN_NONE
;
979 m_btnWid
= m_btnHei
= -1;
988 m_timeCanAcceptClick
= 0;
990 m_resetFocus
= false;
991 m_hasTcBgCol
= false;
994 bool wxComboCtrlBase
::Create(wxWindow
*parent
,
996 const wxString
& value
,
1000 const wxValidator
& validator
,
1001 const wxString
& name
)
1003 if ( !wxControl
::Create(parent
,
1007 style
| wxWANTS_CHARS
,
1012 m_valueString
= value
;
1016 m_marginLeft
= GetNativeTextIndent();
1018 m_iFlags
|= wxCC_IFLAG_CREATED
;
1020 // If x and y indicate valid size, wxSizeEvent won't be
1021 // emitted automatically, so we need to add artifical one.
1022 if ( size
.x
> 0 && size
.y
> 0 )
1024 wxSizeEvent
evt(size
,GetId());
1025 GetEventHandler()->AddPendingEvent(evt
);
1031 void wxComboCtrlBase
::InstallInputHandlers()
1035 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
1036 m_text
->PushEventHandler(m_textEvtHandler
);
1041 wxComboCtrlBase
::CreateTextCtrl(int style
)
1043 if ( !(m_windowStyle
& wxCB_READONLY
) )
1048 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
1049 // not used by the wxPropertyGrid and therefore the tab is processed by
1050 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
1051 // navigation event is then sent to the wrong window.
1052 style
|= wxTE_PROCESS_TAB
| m_textCtrlStyle
;
1054 if ( HasFlag(wxTE_PROCESS_ENTER
) )
1055 style
|= wxTE_PROCESS_ENTER
;
1057 // Ignore EVT_TEXT generated by the constructor (but only
1058 // if the event redirector already exists)
1059 // NB: This must be " = 1" instead of "++";
1060 if ( m_textEvtHandler
)
1061 m_ignoreEvtText
= 1;
1063 m_ignoreEvtText
= 0;
1065 m_text
= new wxComboCtrlTextCtrl();
1066 m_text
->Create(this, wxID_ANY
, m_valueString
,
1067 wxDefaultPosition
, wxSize(10,-1),
1069 m_text
->SetHint(m_hintText
);
1073 void wxComboCtrlBase
::OnThemeChange()
1075 // Because wxComboCtrl has transparent parts on most platforms, we
1076 // don't want to touch the actual background colour. Instead, we just
1077 // usually re-obtain m_tcBgCol here.
1079 #if defined(__WXMSW__) || defined(__WXGTK__)
1080 wxVisualAttributes vattrs
= wxComboBox
::GetClassDefaultAttributes();
1082 wxVisualAttributes vattrs
;
1083 vattrs
.colFg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1084 vattrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1087 if ( !m_hasTcBgCol
)
1088 m_tcBgCol
= vattrs
.colBg
;
1091 // Only change the colours if application has not specified
1095 SetOwnForegroundColour(vattrs
.colFg
);
1097 if ( !HasTransparentBackground() )
1099 SetOwnBackgroundColour(GetParent()->GetBackgroundColour());
1101 #endif // !__WXMAC__
1104 wxComboCtrlBase
::~wxComboCtrlBase()
1109 #if INSTALL_TOPLEV_HANDLER
1110 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
1111 m_toplevEvtHandler
= NULL
;
1117 m_text
->RemoveEventHandler(m_textEvtHandler
);
1119 delete m_textEvtHandler
;
1123 // ----------------------------------------------------------------------------
1125 // ----------------------------------------------------------------------------
1127 // Recalculates button and textctrl areas
1128 void wxComboCtrlBase
::CalculateAreas( int btnWidth
)
1130 wxSize sz
= GetClientSize();
1131 int customBorder
= m_widthCustomBorder
;
1132 int btnBorder
; // border for button only
1134 // check if button should really be outside the border: we'll do it it if
1135 // its platform default or bitmap+pushbutton background is used, but not if
1136 // there is vertical size adjustment or horizontal spacing.
1137 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
1138 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
1139 m_btnSpacingX
== 0 &&
1142 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
1145 else if ( (m_iFlags
& wxCC_BUTTON_COVERS_BORDER
) &&
1146 m_btnSpacingX
== 0 && !m_bmpNormal
.Ok() )
1148 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1153 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
1154 btnBorder
= customBorder
;
1157 // Defaul indentation
1158 if ( m_marginLeft
< 0 )
1159 m_marginLeft
= GetNativeTextIndent();
1161 int butWidth
= btnWidth
;
1163 if ( butWidth
<= 0 )
1164 butWidth
= m_btnWidDefault
;
1166 m_btnWidDefault
= butWidth
;
1168 if ( butWidth
<= 0 )
1171 int butHeight
= sz
.y
- btnBorder
*2;
1173 // Adjust button width
1175 butWidth
= m_btnWid
;
1178 // Adjust button width to match aspect ratio
1179 // (but only if control is smaller than best size).
1180 int bestHeight
= GetBestSize().y
;
1181 int height
= GetSize().y
;
1183 if ( height
< bestHeight
)
1185 // Make very small buttons square, as it makes
1186 // them accommodate arrow image better and still
1189 butWidth
= (height
*butWidth
)/bestHeight
;
1191 butWidth
= butHeight
;
1195 // Adjust button height
1197 butHeight
= m_btnHei
;
1199 // Use size of normal bitmap if...
1202 // button width is set to default and blank button bg is not drawn
1203 if ( m_bmpNormal
.Ok() )
1205 int bmpReqWidth
= m_bmpNormal
.GetWidth();
1206 int bmpReqHeight
= m_bmpNormal
.GetHeight();
1208 // If drawing blank button background, we need to add some margin.
1209 if ( m_blankButtonBg
)
1211 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
1212 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
1215 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
1216 butWidth
= bmpReqWidth
;
1217 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
1218 butHeight
= bmpReqHeight
;
1220 // Need to fix height?
1221 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
1223 int newY
= butHeight
+(customBorder
*2);
1224 SetClientSize(wxDefaultCoord
,newY
);
1225 if ( m_bmpNormal
.Ok() || m_btnArea
.width
!= butWidth
|| m_btnArea
.height
!= butHeight
)
1226 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1228 m_iFlags
&= ~wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
1234 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
1236 m_btnSize
.x
= butWidth
;
1237 m_btnSize
.y
= butHeight
;
1239 m_btnArea
.x
= ( m_btnSide
==wxRIGHT ? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
1240 m_btnArea
.y
= btnBorder
+ FOCUS_RING
;
1241 m_btnArea
.width
= butAreaWid
;
1242 m_btnArea
.height
= sz
.y
- ((btnBorder
+FOCUS_RING
)*2);
1244 m_tcArea
.x
= ( m_btnSide
==wxRIGHT ?
0 : butAreaWid
) + customBorder
+ FOCUS_RING
;
1245 m_tcArea
.y
= customBorder
+ FOCUS_RING
;
1246 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2) - (FOCUS_RING
*2);
1247 m_tcArea
.height
= sz
.y
- ((customBorder
+FOCUS_RING
)*2);
1252 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
1253 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
1258 void wxComboCtrlBase
::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
1263 wxSize sz
= GetClientSize();
1265 int customBorder
= m_widthCustomBorder
;
1266 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
1270 if ( !m_widthCustomPaint
)
1272 // No special custom paint area - we can use 0 left margin
1274 if ( m_text
->SetMargins(0) )
1275 textCtrlXAdjust
= 0;
1276 x
= m_tcArea
.x
+ m_marginLeft
+ textCtrlXAdjust
;
1280 // There is special custom paint area - it is better to
1281 // use some margin with the wxTextCtrl.
1282 m_text
->SetMargins(m_marginLeft
);
1283 x
= m_tcArea
.x
+ m_widthCustomPaint
+
1284 m_marginLeft
+ textCtrlXAdjust
;
1287 // Centre textctrl vertically, if needed
1288 #if !TEXTCTRL_TEXT_CENTERED
1289 int tcSizeY
= m_text
->GetBestSize().y
;
1290 int diff0
= sz
.y
- tcSizeY
;
1291 int y
= textCtrlYAdjust
+ (diff0
/2);
1293 wxUnusedVar(textCtrlYAdjust
);
1297 if ( y
< customBorder
)
1302 m_tcArea
.width
- m_tcArea
.x
- x
,
1305 // Make sure textctrl doesn't exceed the bottom custom border
1306 wxSize tsz
= m_text
->GetSize();
1307 int diff1
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1310 tsz
.y
= tsz
.y
- diff1
- 1;
1311 m_text
->SetSize(tsz
);
1316 // If it has border, have textctrl fill the entire text field.
1317 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1319 m_tcArea
.width
- m_widthCustomPaint
,
1324 wxSize wxComboCtrlBase
::DoGetBestSize() const
1326 wxSize
sizeText(150,0);
1329 sizeText
= m_text
->GetBestSize();
1331 // TODO: Better method to calculate close-to-native control height.
1335 fhei
= (m_font
.GetPointSize()*2) + 5;
1336 else if ( wxNORMAL_FONT
->Ok() )
1337 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1339 fhei
= sizeText
.y
+ 4;
1341 // Need to force height to accomodate bitmap?
1342 int btnSizeY
= m_btnSize
.y
;
1343 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1346 // Control height doesn't depend on border
1349 int border = m_windowStyle & wxBORDER_MASK;
1350 if ( border == wxSIMPLE_BORDER )
1352 else if ( border == wxNO_BORDER )
1353 fhei += (m_widthCustomBorder*2);
1359 // Final adjustments
1365 // these are the numbers from the HIG:
1366 switch ( m_windowVariant
)
1368 case wxWINDOW_VARIANT_NORMAL
:
1372 case wxWINDOW_VARIANT_SMALL
:
1375 case wxWINDOW_VARIANT_MINI
:
1381 fhei
+= 2 * FOCUS_RING
;
1382 int width
= sizeText
.x
+ FOCUS_RING
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
;
1384 wxSize
ret(width
, fhei
);
1389 void wxComboCtrlBase
::OnSizeEvent( wxSizeEvent
& event
)
1394 // defined by actual wxComboCtrls
1400 // ----------------------------------------------------------------------------
1401 // standard operations
1402 // ----------------------------------------------------------------------------
1404 bool wxComboCtrlBase
::Enable(bool enable
)
1406 if ( !wxControl
::Enable(enable
) )
1410 m_btn
->Enable(enable
);
1412 m_text
->Enable(enable
);
1419 bool wxComboCtrlBase
::Show(bool show
)
1421 if ( !wxControl
::Show(show
) )
1433 bool wxComboCtrlBase
::SetFont ( const wxFont
& font
)
1435 if ( !wxControl
::SetFont(font
) )
1440 // Without hiding the wxTextCtrl there would be some
1441 // visible 'flicker' (at least on Windows XP).
1443 m_text
->SetFont(font
);
1452 void wxComboCtrlBase
::DoSetToolTip(wxToolTip
*tooltip
)
1454 wxControl
::DoSetToolTip(tooltip
);
1456 // Set tool tip for button and text box
1459 const wxString
&tip
= tooltip
->GetTip();
1460 if ( m_text
) m_text
->SetToolTip(tip
);
1461 if ( m_btn
) m_btn
->SetToolTip(tip
);
1465 if ( m_text
) m_text
->SetToolTip( NULL
);
1466 if ( m_btn
) m_btn
->SetToolTip( NULL
);
1469 #endif // wxUSE_TOOLTIPS
1471 bool wxComboCtrlBase
::SetForegroundColour(const wxColour
& colour
)
1473 if ( wxControl
::SetForegroundColour(colour
) )
1476 m_text
->SetForegroundColour(colour
);
1482 bool wxComboCtrlBase
::SetBackgroundColour(const wxColour
& colour
)
1485 m_text
->SetBackgroundColour(colour
);
1487 m_hasTcBgCol
= true;
1491 wxColour wxComboCtrlBase
::GetBackgroundColour() const
1494 return m_text
->GetBackgroundColour();
1498 // ----------------------------------------------------------------------------
1500 // ----------------------------------------------------------------------------
1502 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1503 // prepare combo box background on area in a way typical on platform
1504 void wxComboCtrlBase
::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1506 wxSize sz
= GetClientSize();
1508 bool doDrawFocusRect
; // also selected
1510 // For smaller size control (and for disabled background) use less spacing
1514 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1517 isEnabled
= IsEnabled();
1518 doDrawFocusRect
= ShouldDrawFocus() && !(m_iFlags
& wxCC_FULL_BUTTON
);
1520 // Windows-style: for smaller size control (and for disabled background) use less spacing
1521 focusSpacingX
= isEnabled ?
2 : 1;
1522 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled ?
2 : 1;
1526 // Drawing a list item
1527 isEnabled
= true; // they are never disabled
1528 doDrawFocusRect
= (flags
& wxCONTROL_SELECTED
) != 0;
1534 // Set the background sub-rectangle for selection, disabled etc
1535 wxRect
selRect(rect
);
1536 selRect
.y
+= focusSpacingY
;
1537 selRect
.height
-= (focusSpacingY
*2);
1541 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1542 wcp
+= m_widthCustomPaint
;
1544 selRect
.x
+= wcp
+ focusSpacingX
;
1545 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1550 bool doDrawSelRect
= true;
1552 // Determine foreground colour
1555 if ( doDrawFocusRect
)
1557 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
);
1559 else if ( m_hasFgCol
)
1561 // Honour the custom foreground colour
1562 fgCol
= GetForegroundColour();
1566 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1571 fgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_GRAYTEXT
);
1574 // Determine background colour
1577 if ( doDrawFocusRect
)
1579 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1581 else if ( m_hasTcBgCol
)
1583 // Honour the custom background colour
1588 #ifndef __WXMAC__ // see note in OnThemeChange
1589 doDrawSelRect
= false;
1590 bgCol
= GetBackgroundColour();
1592 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1598 #ifndef __WXMAC__ // see note in OnThemeChange
1599 bgCol
= GetBackgroundColour();
1601 bgCol
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1605 dc
.SetTextForeground( fgCol
);
1606 dc
.SetBrush( bgCol
);
1607 if ( doDrawSelRect
)
1610 dc
.DrawRectangle( selRect
);
1613 // Don't clip exactly to the selection rectangle so we can draw
1614 // to the non-selected area in front of it.
1615 wxRect
clipRect(rect
.x
,rect
.y
,
1616 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1617 dc
.SetClippingRegion(clipRect
);
1620 // Save the library size a bit for platforms that re-implement this.
1621 void wxComboCtrlBase
::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1626 void wxComboCtrlBase
::DrawButton( wxDC
& dc
, const wxRect
& rect
, int flags
)
1628 int drawState
= m_btnState
;
1630 if ( (m_iFlags
& wxCC_BUTTON_STAYS_DOWN
) &&
1631 GetPopupWindowState() >= Animating
)
1632 drawState
|= wxCONTROL_PRESSED
;
1634 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1635 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1639 // Make sure area is not larger than the control
1640 if ( drawRect
.y
< rect
.y
)
1641 drawRect
.y
= rect
.y
;
1642 if ( drawRect
.height
> rect
.height
)
1643 drawRect
.height
= rect
.height
;
1645 bool enabled
= IsEnabled();
1648 drawState
|= wxCONTROL_DISABLED
;
1650 if ( !m_bmpNormal
.Ok() )
1652 if ( flags
& Button_BitmapOnly
)
1655 // Need to clear button background even if m_btn is present
1656 if ( (flags
& Button_PaintBackground
) &&
1657 (!HasTransparentBackground() ||
1658 !(m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)) )
1662 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1663 bgCol
= GetParent()->GetBackgroundColour();
1665 bgCol
= GetBackgroundColour();
1669 dc
.DrawRectangle(rect
);
1672 // Draw standard button
1673 wxRendererNative
::Get().DrawComboBoxDropButton(this,
1685 pBmp
= &m_bmpDisabled
;
1686 else if ( m_btnState
& wxCONTROL_PRESSED
)
1687 pBmp
= &m_bmpPressed
;
1688 else if ( m_btnState
& wxCONTROL_CURRENT
)
1691 pBmp
= &m_bmpNormal
;
1693 if ( m_blankButtonBg
)
1695 // If using blank button background, we need to clear its background
1696 // with button face colour instead of colour for rest of the control.
1697 if ( flags
& Button_PaintBackground
)
1699 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1700 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1703 dc
.DrawRectangle(rect
);
1706 if ( !(flags
& Button_BitmapOnly
) )
1708 wxRendererNative
::Get().DrawPushButton(this,
1717 // Need to clear button background even if m_btn is present
1718 // (assume non-button background was cleared just before this call so brushes are good)
1719 if ( flags
& Button_PaintBackground
)
1720 dc
.DrawRectangle(rect
);
1723 // Draw bitmap centered in drawRect
1724 dc
.DrawBitmap(*pBmp
,
1725 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1726 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1731 void wxComboCtrlBase
::RecalcAndRefresh()
1735 wxSizeEvent
evt(GetSize(),GetId());
1736 GetEventHandler()->ProcessEvent(evt
);
1741 // ----------------------------------------------------------------------------
1742 // miscellaneous event handlers
1743 // ----------------------------------------------------------------------------
1745 void wxComboCtrlBase
::OnTextCtrlEvent(wxCommandEvent
& event
)
1747 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1749 if ( m_ignoreEvtText
> 0 )
1756 // Change event id, object and string before relaying it forward
1757 event
.SetId(GetId());
1758 wxString s
= event
.GetString();
1759 event
.SetEventObject(this);
1764 // call if cursor is on button area or mouse is captured for the button
1765 bool wxComboCtrlBase
::HandleButtonMouseEvent( wxMouseEvent
& event
,
1768 int type
= event
.GetEventType();
1770 if ( type
== wxEVT_MOTION
)
1772 if ( (flags
& wxCC_MF_ON_BUTTON
) &&
1773 IsPopupWindowState(Hidden
) )
1775 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1777 // Mouse hover begins
1778 m_btnState
|= wxCONTROL_CURRENT
;
1779 if ( HasCapture() ) // Retain pressed state.
1780 m_btnState
|= wxCONTROL_PRESSED
;
1784 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1787 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1791 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1793 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1795 m_btnState
|= wxCONTROL_PRESSED
;
1798 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1801 // If showing popup now, do not capture mouse or there will be interference
1805 else if ( type
== wxEVT_LEFT_UP
)
1808 // Only accept event if mouse was left-press was previously accepted
1812 if ( m_btnState
& wxCONTROL_PRESSED
)
1814 // If mouse was inside, fire the click event.
1815 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1817 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1821 m_btnState
&= ~(wxCONTROL_PRESSED
);
1825 else if ( type
== wxEVT_LEAVE_WINDOW
)
1827 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1829 m_btnState
&= ~(wxCONTROL_CURRENT
);
1832 if ( IsPopupWindowState(Hidden
) )
1834 m_btnState
&= ~(wxCONTROL_PRESSED
);
1842 // Never have 'hot' state when popup is being shown
1843 // (this is mostly needed because of the animation).
1844 if ( !IsPopupWindowState(Hidden
) )
1845 m_btnState
&= ~wxCONTROL_CURRENT
;
1850 // returns true if event was consumed or filtered
1851 bool wxComboCtrlBase
::PreprocessMouseEvent( wxMouseEvent
& event
,
1852 int WXUNUSED(flags
) )
1854 wxLongLong t
= ::wxGetLocalTimeMillis();
1855 int evtType
= event
.GetEventType();
1857 #if USES_WXPOPUPWINDOW || USES_GENERICTLW
1858 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1860 if ( IsPopupWindowState(Visible
) &&
1861 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1869 // Filter out clicks on button immediately after popup dismiss
1870 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1872 event
.SetEventType(0);
1879 void wxComboCtrlBase
::HandleNormalMouseEvent( wxMouseEvent
& event
)
1881 int evtType
= event
.GetEventType();
1883 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1884 (m_windowStyle
& wxCB_READONLY
) )
1886 if ( GetPopupWindowState() >= Animating
)
1888 #if USES_WXPOPUPWINDOW
1889 // Click here always hides the popup.
1890 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1896 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1898 // In read-only mode, clicking the text is the
1899 // same as clicking the button.
1902 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1904 //if ( m_popupInterface->CycleValue() )
1906 if ( m_popupInterface
)
1907 m_popupInterface
->OnComboDoubleClick();
1911 else if ( evtType
== wxEVT_MOUSEWHEEL
)
1913 if ( IsPopupShown() )
1915 // relay (some) mouse events to the popup
1916 m_popup
->GetEventHandler()->ProcessEvent(event
);
1918 else if ( event
.GetWheelAxis() == 0 &&
1919 event
.GetWheelRotation() != 0 &&
1920 event
.GetModifiers() == 0 )
1922 // Translate mousewheel actions into key up/down. This is
1923 // the simplest way of getting native behaviour: scrolling the
1924 // wheel moves selection up/down by one item.
1925 wxKeyEvent
kevent(wxEVT_KEY_DOWN
);
1926 kevent
.m_keyCode
= event
.GetWheelRotation() > 0
1929 GetEventHandler()->ProcessEvent(kevent
);
1942 void wxComboCtrlBase
::OnKeyEvent(wxKeyEvent
& event
)
1944 if ( IsPopupShown() )
1946 // pass it to the popped up control
1947 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1951 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1953 if ( mainCtrl
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
1955 if ( mainCtrl
->HandleAsNavigationKey(event
) )
1959 if ( IsKeyPopupToggle(event
) )
1965 int comboStyle
= GetWindowStyle();
1966 wxComboPopup
* popupInterface
= GetPopupControl();
1968 if ( !popupInterface
)
1974 int keycode
= event
.GetKeyCode();
1976 if ( (comboStyle
& wxCB_READONLY
) ||
1977 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1979 popupInterface
->OnComboKeyEvent(event
);
1986 void wxComboCtrlBase
::OnCharEvent(wxKeyEvent
& event
)
1988 if ( IsPopupShown() )
1990 // pass it to the popped up control
1991 GetPopupControl()->GetControl()->GetEventHandler()->ProcessEvent(event
);
1995 wxComboPopup
* popupInterface
= GetPopupControl();
1996 if ( popupInterface
)
1998 popupInterface
->OnComboCharEvent(event
);
2007 void wxComboCtrlBase
::OnFocusEvent( wxFocusEvent
& event
)
2009 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
2011 wxWindow
* tc
= GetTextCtrl();
2012 if ( tc
&& tc
!= DoFindFocus() )
2021 void wxComboCtrlBase
::OnIdleEvent( wxIdleEvent
& WXUNUSED(event
) )
2025 m_resetFocus
= false;
2026 wxWindow
* tc
= GetTextCtrl();
2032 void wxComboCtrlBase
::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
2035 // left margin may also have changed
2036 if ( !(m_iFlags
& wxCC_IFLAG_LEFT_MARGIN_SET
) )
2037 m_marginLeft
= GetNativeTextIndent();
2041 // ----------------------------------------------------------------------------
2043 // ----------------------------------------------------------------------------
2045 // Create popup window and the child control
2046 void wxComboCtrlBase
::CreatePopup()
2048 wxComboPopup
* popupInterface
= m_popupInterface
;
2053 #ifdef wxComboPopupWindowBase2
2054 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
2056 #if !USES_GENERICTLW
2057 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
2059 int tlwFlags
= wxNO_BORDER
;
2060 #ifdef wxCC_GENERIC_TLW_IS_FRAME
2061 tlwFlags
|= wxFRAME_NO_TASKBAR
;
2064 #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW
2065 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
,
2066 wxPoint(-21,-21), wxSize(20, 20),
2069 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
2070 wxPoint(-21,-21), wxSize(20, 20),
2074 m_popupWinType
= SECONDARY_POPUP_TYPE
;
2077 #endif // wxComboPopupWindowBase2
2079 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
2080 m_popupWinType
= PRIMARY_POPUP_TYPE
;
2082 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
2083 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
2086 popupInterface
->Create(m_winPopup
);
2087 m_popup
= popup
= popupInterface
->GetControl();
2089 m_popupEvtHandler
= new wxComboPopupEvtHandler(this);
2090 popup
->PushEventHandler( m_popupEvtHandler
);
2092 // This may be helpful on some platforms
2093 // (eg. it bypasses a wxGTK popupwindow bug where
2094 // window is not initially hidden when it should be)
2097 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
2100 // Destroy popup window and the child control
2101 void wxComboCtrlBase
::DestroyPopup()
2106 m_popup
->RemoveEventHandler(m_popupEvtHandler
);
2108 wxDELETE(m_popupEvtHandler
);
2110 wxDELETE(m_popupInterface
);
2114 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
2115 wxDELETE(m_popupWinEvtHandler
);
2116 m_winPopup
->Destroy();
2123 void wxComboCtrlBase
::DoSetPopupControl(wxComboPopup
* iface
)
2125 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
2129 iface
->InitBase(this);
2132 m_popupInterface
= iface
;
2134 if ( !iface
->LazyCreate() )
2143 // This must be done after creation
2144 if ( !m_valueString
.empty() )
2146 iface
->SetStringValue(m_valueString
);
2151 // Ensures there is atleast the default popup
2152 void wxComboCtrlBase
::EnsurePopupControl()
2154 if ( !m_popupInterface
)
2155 SetPopupControl(NULL
);
2158 void wxComboCtrlBase
::OnButtonClick()
2160 // Derived classes can override this method for totally custom
2162 switch ( GetPopupWindowState() )
2179 void wxComboCtrlBase
::Popup()
2181 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_DROPDOWN
, GetId());
2182 event
.SetEventObject(this);
2183 HandleWindowEvent(event
);
2188 void wxComboCtrlBase
::ShowPopup()
2190 EnsurePopupControl();
2191 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
2193 if ( IsPopupWindowState(Animating
) )
2198 // Space above and below
2204 wxSize ctrlSz
= GetSize();
2206 screenHeight
= wxSystemSettings
::GetMetric( wxSYS_SCREEN_Y
);
2207 scrPos
= GetParent()->ClientToScreen(GetPosition());
2209 spaceAbove
= scrPos
.y
;
2210 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
2212 maxHeightPopup
= spaceBelow
;
2213 if ( spaceAbove
> spaceBelow
)
2214 maxHeightPopup
= spaceAbove
;
2217 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
2219 if ( widthPopup
< m_widthMinPopup
)
2220 widthPopup
= m_widthMinPopup
;
2222 wxWindow
* winPopup
= m_winPopup
;
2225 // Need to disable tab traversal of parent
2227 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
2228 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
2229 // that if transient popup is open, then tab traversal is to be ignored.
2230 // However, I think this code would still be needed for cases where
2231 // transient popup doesn't work yet (wxWinCE?).
2232 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
2233 wxWindow
* parent
= mainCtrl
->GetParent();
2234 int parentFlags
= parent
->GetWindowStyle();
2235 if ( parentFlags
& wxTAB_TRAVERSAL
)
2237 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
2238 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
2244 winPopup
= m_winPopup
;
2254 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
2256 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
2257 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
2260 popup
->SetSize(adjustedSize
);
2262 m_popupInterface
->OnPopup();
2265 // Reposition and resize popup window
2268 wxSize szp
= popup
->GetSize();
2271 int popupY
= scrPos
.y
+ ctrlSz
.y
;
2273 // Default anchor is wxLEFT
2274 int anchorSide
= m_anchorSide
;
2276 anchorSide
= wxLEFT
;
2278 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
2279 int leftX
= scrPos
.x
- m_extLeft
;
2281 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
2284 int screenWidth
= wxSystemSettings
::GetMetric( wxSYS_SCREEN_X
);
2286 // If there is not enough horizontal space, anchor on the other side.
2287 // If there is no space even then, place the popup at x 0.
2288 if ( anchorSide
== wxRIGHT
)
2292 if ( (leftX
+szp
.x
) < screenWidth
)
2293 anchorSide
= wxLEFT
;
2300 if ( (leftX
+szp
.x
) >= screenWidth
)
2303 anchorSide
= wxRIGHT
;
2309 // Select x coordinate according to the anchor side
2310 if ( anchorSide
== wxRIGHT
)
2312 else if ( anchorSide
== wxLEFT
)
2317 int showFlags
= CanDeferShow
;
2319 if ( spaceBelow
< szp
.y
)
2321 popupY
= scrPos
.y
- szp
.y
;
2322 showFlags
|= ShowAbove
;
2325 #if INSTALL_TOPLEV_HANDLER
2326 // Put top level window event handler into place
2327 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
2329 if ( !m_toplevEvtHandler
)
2330 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
2332 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2334 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
2335 toplev
->PushEventHandler( m_toplevEvtHandler
);
2339 // Set string selection (must be this way instead of SetStringSelection)
2342 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2343 m_text
->SelectAll();
2345 m_popupInterface
->SetStringValue( m_text
->GetValue() );
2349 // This is neede since focus/selection indication may change when popup is shown
2353 // This must be after SetStringValue
2354 m_popupWinState
= Animating
;
2356 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
2359 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
2360 AnimateShow( popupWinRect
, showFlags
) )
2362 DoShowPopup( popupWinRect
, showFlags
);
2366 bool wxComboCtrlBase
::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
2371 void wxComboCtrlBase
::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
2373 wxWindow
* winPopup
= m_winPopup
;
2375 if ( IsPopupWindowState(Animating
) )
2377 // Make sure the popup window is shown in the right position.
2378 // Should not matter even if animation already did this.
2380 // Some platforms (GTK) may like SetSize and Move to be separate
2381 // (though the bug was probably fixed).
2382 winPopup
->SetSize( rect
);
2384 #if USES_WXPOPUPTRANSIENTWINDOW
2385 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2386 ((wxPopupTransientWindow
*)winPopup
)->Popup(m_popup
);
2391 m_popupWinState
= Visible
;
2393 // If popup window was a generic top-level window, or the
2394 // wxPopupWindow implemenation on this platform is classified as
2395 // perfect, then we should be able to safely set focus to the popup
2397 if ( IsPopupWinTypePerfect(m_popupWinType
) )
2398 m_popup
->SetFocus();
2400 else if ( IsPopupWindowState(Hidden
) )
2402 // Animation was aborted
2404 wxASSERT( !winPopup
->IsShown() );
2406 m_popupWinState
= Hidden
;
2412 void wxComboCtrlBase
::OnPopupDismiss(bool generateEvent
)
2414 // Just in case, avoid double dismiss
2415 if ( IsPopupWindowState(Hidden
) )
2418 // This must be set before focus - otherwise there will be recursive
2419 // OnPopupDismisses.
2420 m_popupWinState
= Hidden
;
2423 m_winPopup
->Disable();
2425 // Inform popup control itself
2426 m_popupInterface
->OnDismiss();
2428 if ( m_popupEvtHandler
)
2429 ((wxComboPopupEvtHandler
*)m_popupEvtHandler
)->OnPopupDismiss();
2431 #if INSTALL_TOPLEV_HANDLER
2432 // Remove top level window event handler
2433 if ( m_toplevEvtHandler
)
2435 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
2437 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
2441 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
2443 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
2444 m_timeCanAcceptClick
+= 150;
2446 // If cursor not on dropdown button, then clear its state
2447 // (technically not required by all ports, but do it for all just in case)
2448 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
2451 // Return parent's tab traversal flag.
2452 // See ShowPopup for notes.
2453 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2455 wxWindow
* parent
= GetParent();
2456 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2457 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2460 // refresh control (necessary even if m_text)
2465 if ( generateEvent
)
2467 wxCommandEvent
event(wxEVT_COMMAND_COMBOBOX_CLOSEUP
, GetId());
2468 event
.SetEventObject(this);
2469 HandleWindowEvent(event
);
2473 void wxComboCtrlBase
::HidePopup(bool generateEvent
)
2475 // Should be able to call this without popup interface
2476 if ( IsPopupWindowState(Hidden
) )
2479 // transfer value and show it in textctrl, if any
2480 if ( !IsPopupWindowState(Animating
) )
2481 SetValueByUser( m_popupInterface
->GetStringValue() );
2485 OnPopupDismiss(generateEvent
);
2488 // ----------------------------------------------------------------------------
2489 // customization methods
2490 // ----------------------------------------------------------------------------
2492 void wxComboCtrlBase
::SetButtonPosition( int width
, int height
,
2493 int side
, int spacingX
)
2498 m_btnSpacingX
= spacingX
;
2500 if ( width
> 0 || height
> 0 || spacingX
)
2501 m_iFlags
|= wxCC_IFLAG_HAS_NONSTANDARD_BUTTON
;
2506 wxSize wxComboCtrlBase
::GetButtonSize()
2508 if ( m_btnSize
.x
> 0 )
2511 wxSize
retSize(m_btnWid
,m_btnHei
);
2513 // Need to call CalculateAreas now if button size is
2514 // is not explicitly specified.
2515 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2519 retSize
= m_btnSize
;
2525 void wxComboCtrlBase
::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2527 const wxBitmap
& bmpPressed
,
2528 const wxBitmap
& bmpHover
,
2529 const wxBitmap
& bmpDisabled
)
2531 m_bmpNormal
= bmpNormal
;
2532 m_blankButtonBg
= blankButtonBg
;
2534 if ( bmpPressed
.Ok() )
2535 m_bmpPressed
= bmpPressed
;
2537 m_bmpPressed
= bmpNormal
;
2539 if ( bmpHover
.Ok() )
2540 m_bmpHover
= bmpHover
;
2542 m_bmpHover
= bmpNormal
;
2544 if ( bmpDisabled
.Ok() )
2545 m_bmpDisabled
= bmpDisabled
;
2547 m_bmpDisabled
= bmpNormal
;
2552 void wxComboCtrlBase
::SetCustomPaintWidth( int width
)
2556 // move textctrl accordingly
2557 wxRect r
= m_text
->GetRect();
2558 int inc
= width
- m_widthCustomPaint
;
2561 m_text
->SetSize( r
);
2564 m_widthCustomPaint
= width
;
2569 bool wxComboCtrlBase
::DoSetMargins(const wxPoint
& margins
)
2571 // For general sanity's sake, we ignore top margin. Instead
2572 // we will always try to center the text vertically.
2575 if ( margins
.x
!= -1 )
2577 m_marginLeft
= margins
.x
;
2578 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2582 m_marginLeft
= GetNativeTextIndent();
2583 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2586 if ( margins
.y
!= -1 )
2596 wxPoint wxComboCtrlBase
::DoGetMargins() const
2598 return wxPoint(m_marginLeft
, -1);
2601 #if WXWIN_COMPATIBILITY_2_8
2602 void wxComboCtrlBase
::SetTextIndent( int indent
)
2606 m_marginLeft
= GetNativeTextIndent();
2607 m_iFlags
&= ~(wxCC_IFLAG_LEFT_MARGIN_SET
);
2611 m_marginLeft
= indent
;
2612 m_iFlags
|= wxCC_IFLAG_LEFT_MARGIN_SET
;
2618 wxCoord wxComboCtrlBase
::GetTextIndent() const
2620 return m_marginLeft
;
2624 wxCoord wxComboCtrlBase
::GetNativeTextIndent() const
2626 return DEFAULT_TEXT_INDENT
;
2629 void wxComboCtrlBase
::SetTextCtrlStyle( int style
)
2631 m_textCtrlStyle
= style
;
2634 m_text
->SetWindowStyle(style
);
2637 // ----------------------------------------------------------------------------
2638 // wxTextEntry interface
2639 // ----------------------------------------------------------------------------
2641 wxString wxComboCtrlBase
::DoGetValue() const
2644 return m_text
->GetValue();
2645 return m_valueString
;
2648 void wxComboCtrlBase
::SetValueWithEvent(const wxString
& value
,
2651 DoSetValue(value
, withEvent ? SetValue_SendEvent
: 0);
2654 void wxComboCtrlBase
::OnSetValue(const wxString
& value
)
2656 // Note: before wxComboCtrl inherited from wxTextEntry,
2657 // this code used to be in SetValueWithEvent().
2659 // Since wxComboPopup may want to paint the combo as well, we need
2660 // to set the string value here (as well as sometimes in ShowPopup).
2661 if ( m_valueString
!= value
)
2664 wxString trueValue
= value
;
2666 // Conform to wxComboBox behavior: read-only control can only accept
2667 // valid list items and empty string
2668 if ( m_popupInterface
&& HasFlag(wxCB_READONLY
) && value
.length() )
2670 found
= m_popupInterface
->FindItem(value
,
2676 m_valueString
= trueValue
;
2678 EnsurePopupControl();
2680 if ( m_popupInterface
)
2681 m_popupInterface
->SetStringValue(trueValue
);
2688 void wxComboCtrlBase
::SetValueByUser(const wxString
& value
)
2690 // NB: Order of function calls is important here. Otherwise
2691 // the SelectAll() may not work.
2695 m_text
->SetValue(value
);
2697 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2698 m_text
->SelectAll();
2704 // In this SetValue variant wxComboPopup::SetStringValue is not called
2705 void wxComboCtrlBase
::SetText(const wxString
& value
)
2707 // Unlike in SetValue(), this must be called here or
2708 // the behaviour will no be consistent in readonlys.
2709 EnsurePopupControl();
2711 m_valueString
= value
;
2716 m_text
->SetValue( value
);
2722 void wxComboCtrlBase
::Copy()
2728 void wxComboCtrlBase
::Cut()
2734 void wxComboCtrlBase
::Paste()
2740 void wxComboCtrlBase
::SetInsertionPoint(long pos
)
2743 m_text
->SetInsertionPoint(pos
);
2746 long wxComboCtrlBase
::GetInsertionPoint() const
2749 return m_text
->GetInsertionPoint();
2754 long wxComboCtrlBase
::GetLastPosition() const
2757 return m_text
->GetLastPosition();
2762 void wxComboCtrlBase
::WriteText(const wxString
& text
)
2766 m_text
->WriteText(text
);
2767 OnSetValue(m_text
->GetValue());
2775 void wxComboCtrlBase
::DoSetValue(const wxString
& value
, int flags
)
2779 if ( flags
& SetValue_SendEvent
)
2780 m_text
->SetValue(value
);
2782 m_text
->ChangeValue(value
);
2788 void wxComboCtrlBase
::Replace(long from
, long to
, const wxString
& value
)
2792 m_text
->Replace(from
, to
, value
);
2793 OnSetValue(m_text
->GetValue());
2797 void wxComboCtrlBase
::Remove(long from
, long to
)
2801 m_text
->Remove(from
, to
);
2802 OnSetValue(m_text
->GetValue());
2806 void wxComboCtrlBase
::SetSelection(long from
, long to
)
2809 m_text
->SetSelection(from
, to
);
2812 void wxComboCtrlBase
::GetSelection(long *from
, long *to
) const
2816 m_text
->GetSelection(from
, to
);
2825 bool wxComboCtrlBase
::IsEditable() const
2828 return m_text
->IsEditable();
2832 void wxComboCtrlBase
::SetEditable(bool editable
)
2835 m_text
->SetEditable(editable
);
2838 void wxComboCtrlBase
::Undo()
2844 void wxComboCtrlBase
::Redo()
2850 bool wxComboCtrlBase
::CanUndo() const
2853 return m_text
->CanUndo();
2858 bool wxComboCtrlBase
::CanRedo() const
2861 return m_text
->CanRedo();
2866 bool wxComboCtrlBase
::SetHint(const wxString
& hint
)
2871 res
= m_text
->SetHint(hint
);
2876 wxString wxComboCtrlBase
::GetHint() const
2881 #endif // wxUSE_COMBOCTRL