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"
32 #include "wx/dcclient.h"
33 #include "wx/settings.h"
34 #include "wx/dialog.h"
38 #include "wx/dcbuffer.h"
39 #include "wx/tooltip.h"
46 // ----------------------------------------------------------------------------
48 // Milliseconds to wait for two mouse-ups after focus inorder
49 // to trigger a double-click.
50 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
52 #define DEFAULT_DROPBUTTON_WIDTH 19
54 #define BMP_BUTTON_MARGIN 4
56 #define DEFAULT_POPUP_HEIGHT 200
58 #define DEFAULT_TEXT_INDENT 3
60 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
63 #if defined(__WXMSW__)
65 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
67 //#undef wxUSE_POPUPWIN
68 //#define wxUSE_POPUPWIN 0
70 #elif defined(__WXGTK__)
72 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
74 #elif defined(__WXMAC__)
76 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
80 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
85 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
86 // what the wxUSE_POPUPWIN says.
87 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
88 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
90 #define wxUSE_POPUPWIN 0
95 #include "wx/popupwin.h"
97 #undef USE_TRANSIENT_POPUP
98 #define USE_TRANSIENT_POPUP 0
102 #if USE_TRANSIENT_POPUP
104 #define wxComboPopupWindowBase wxPopupTransientWindow
105 #define INSTALL_TOPLEV_HANDLER 0
109 #define wxComboPopupWindowBase wxPopupWindow
110 #define INSTALL_TOPLEV_HANDLER 1
114 #define wxComboPopupWindowBase wxDialog
115 #define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
123 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
127 // ----------------------------------------------------------------------------
128 // wxComboFrameEventHandler takes care of hiding the popup when events happen
129 // in its top level parent.
130 // ----------------------------------------------------------------------------
132 #if INSTALL_TOPLEV_HANDLER
135 // This will no longer be necessary after wxTransientPopupWindow
136 // works well on all platforms.
139 class wxComboFrameEventHandler
: public wxEvtHandler
142 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
143 ~wxComboFrameEventHandler();
147 void OnIdle( wxIdleEvent
& event
);
148 void OnMouseEvent( wxMouseEvent
& event
);
149 void OnActivate( wxActivateEvent
& event
);
150 void OnResize( wxSizeEvent
& event
);
151 void OnMove( wxMoveEvent
& event
);
152 void OnMenuEvent( wxMenuEvent
& event
);
153 void OnClose( wxCloseEvent
& event
);
156 wxWindow
* m_focusStart
;
157 wxComboCtrlBase
* m_combo
;
160 DECLARE_EVENT_TABLE()
163 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
164 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
165 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
166 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
167 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
168 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
169 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
170 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
171 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
172 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
175 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
181 wxComboFrameEventHandler::~wxComboFrameEventHandler()
185 void wxComboFrameEventHandler::OnPopup()
187 m_focusStart
= ::wxWindow::FindFocus();
190 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
192 wxWindow
* winFocused
= ::wxWindow::FindFocus();
194 wxWindow
* popup
= m_combo
->GetPopupControl();
195 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
198 winFocused
!= m_focusStart
&&
199 winFocused
!= popup
&&
200 winFocused
->GetParent() != popup
&&
201 winFocused
!= winpopup
&&
202 winFocused
->GetParent() != winpopup
&&
203 winFocused
!= m_combo
&&
204 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
207 m_combo
->HidePopup();
213 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
215 m_combo
->HidePopup();
219 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
221 m_combo
->HidePopup();
225 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
227 m_combo
->HidePopup();
231 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
233 m_combo
->HidePopup();
237 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
239 m_combo
->HidePopup();
243 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
245 m_combo
->HidePopup();
249 #endif // INSTALL_TOPLEV_HANDLER
251 // ----------------------------------------------------------------------------
252 // wxComboPopupWindow is wxPopupWindow customized for
254 // ----------------------------------------------------------------------------
256 class wxComboPopupWindow
: public wxComboPopupWindowBase
260 wxComboPopupWindow( wxComboCtrlBase
*parent
, int style
= wxBORDER_NONE
);
262 #if USE_TRANSIENT_POPUP
263 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
266 void OnKeyEvent(wxKeyEvent
& event
);
268 void OnMouseEvent( wxMouseEvent
& event
);
270 void OnActivate( wxActivateEvent
& event
);
275 #if USE_TRANSIENT_POPUP
276 virtual void OnDismiss();
280 DECLARE_EVENT_TABLE()
284 BEGIN_EVENT_TABLE(wxComboPopupWindow
, wxComboPopupWindowBase
)
285 EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent
)
287 EVT_ACTIVATE(wxComboPopupWindow::OnActivate
)
289 EVT_KEY_DOWN(wxComboPopupWindow::OnKeyEvent
)
290 EVT_KEY_UP(wxComboPopupWindow::OnKeyEvent
)
294 wxComboPopupWindow::wxComboPopupWindow( wxComboCtrlBase
*parent
,
297 : wxComboPopupWindowBase(parent
,style
)
299 : wxComboPopupWindowBase(parent
,
309 void wxComboPopupWindow::OnKeyEvent( wxKeyEvent
& event
)
311 // Relay keyboard event to the main child controls
312 // (just skipping may just cause the popup to close)
313 wxWindowList children
= GetChildren();
314 wxWindowList::iterator node
= children
.begin();
315 wxWindow
* child
= (wxWindow
*)*node
;
316 child
->AddPendingEvent(event
);
319 void wxComboPopupWindow::OnMouseEvent( wxMouseEvent
& event
)
325 void wxComboPopupWindow::OnActivate( wxActivateEvent
& event
)
327 if ( !event
.GetActive() )
329 // Tell combo control that we are dismissed.
330 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
332 wxASSERT( combo
->IsKindOf(CLASSINFO(wxComboCtrl
)) );
341 #if USE_TRANSIENT_POPUP
342 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
344 return wxComboPopupWindowBase::ProcessLeftDown(event
);
348 #if USE_TRANSIENT_POPUP
349 // First thing that happens when a transient popup closes is that this method gets called.
350 void wxComboPopupWindow::OnDismiss()
352 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
353 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
354 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
356 combo
->OnPopupDismiss();
360 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 wxComboPopup::~wxComboPopup()
369 void wxComboPopup::OnPopup()
373 void wxComboPopup::OnDismiss()
377 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
379 int WXUNUSED(maxHeight
) )
381 return wxSize(minWidth
,prefHeight
);
384 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
385 wxDC
& dc
, const wxRect
& rect
)
387 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
389 combo
->DrawFocusBackground(dc
,rect
,0);
391 dc
.DrawText( combo
->GetValue(),
392 rect
.x
+ combo
->GetTextIndent(),
393 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
397 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
399 DefaultPaintComboControl(m_combo
,dc
,rect
);
402 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
407 void wxComboPopup::OnComboDoubleClick()
411 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
415 bool wxComboPopup::LazyCreate()
420 void wxComboPopup::Dismiss()
422 m_combo
->HidePopup();
425 // ----------------------------------------------------------------------------
427 // ----------------------------------------------------------------------------
430 // This is pushed to the event handler queue of either combo box
431 // or its textctrl (latter if not readonly combo).
433 class wxComboBoxExtraInputHandler
: public wxEvtHandler
437 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
442 ~wxComboBoxExtraInputHandler() { }
443 void OnKey(wxKeyEvent
& event
);
444 void OnFocus(wxFocusEvent
& event
);
447 wxComboCtrlBase
* m_combo
;
450 DECLARE_EVENT_TABLE()
454 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
455 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
456 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
460 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
462 int keycode
= event
.GetKeyCode();
464 if ( keycode
== WXK_TAB
&& !m_combo
->IsPopupShown() )
466 wxNavigationKeyEvent evt
;
467 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
468 (!event
.ShiftDown()?wxNavigationKeyEvent::IsForward
:
469 wxNavigationKeyEvent::IsBackward
));
470 evt
.SetEventObject(m_combo
);
471 m_combo
->GetParent()->GetEventHandler()->AddPendingEvent(evt
);
475 if ( m_combo
->IsPopupShown() )
477 // pass it to the popped up control
478 m_combo
->GetPopupControl()->GetControl()->AddPendingEvent(event
);
482 int comboStyle
= m_combo
->GetWindowStyle();
483 wxComboPopup
* popupInterface
= m_combo
->GetPopupControl();
485 if ( !popupInterface
)
491 if ( (comboStyle
& wxCB_READONLY
) ||
492 ( keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
)
495 // Alternate keys: UP and DOWN show the popup instead of cycling
496 if ( (comboStyle
& wxCC_ALT_KEYS
) )
498 if ( keycode
== WXK_UP
|| keycode
== WXK_DOWN
)
500 m_combo
->OnButtonClick();
507 popupInterface
->OnComboKeyEvent(event
);
514 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
516 // FIXME: This code does run when control is clicked,
517 // yet on Windows it doesn't select all the text.
518 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
520 if ( m_combo
->GetTextCtrl() )
521 m_combo
->GetTextCtrl()->SelectAll();
523 m_combo
->SetSelection(-1,-1);
526 if ( event
.GetId() != m_combo
->GetId() )
528 // Add textctrl set focus events as combo set focus events
529 // NOTE: Simply changing the event and skipping didn't seem
531 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
532 evt2
.SetEventObject(m_combo
);
533 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
543 // This is pushed to the event handler queue of the control in popup.
546 class wxComboPopupExtraEventHandler
: public wxEvtHandler
550 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
554 m_beenInside
= false;
556 ~wxComboPopupExtraEventHandler() { }
558 void OnMouseEvent( wxMouseEvent
& event
);
560 // Called from wxComboCtrlBase::OnPopupDismiss
561 void OnPopupDismiss()
563 m_beenInside
= false;
567 wxComboCtrlBase
* m_combo
;
572 DECLARE_EVENT_TABLE()
576 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
577 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
581 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
583 wxPoint pt
= event
.GetPosition();
584 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
585 int evtType
= event
.GetEventType();
586 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
588 if ( evtType
== wxEVT_MOTION
||
589 evtType
== wxEVT_LEFT_DOWN
||
590 evtType
== wxEVT_RIGHT_DOWN
)
592 // Block motion and click events outside the popup
599 else if ( evtType
== wxEVT_LEFT_UP
)
601 // Don't let left-down events in if outside
602 if ( evtType
== wxEVT_LEFT_DOWN
)
617 // Some mouse events to popup that happen outside it, before cursor
618 // has been inside the popu, need to be ignored by it but relayed to
621 wxWindow
* btn
= m_combo
->GetButton();
623 btn
->GetEventHandler()->AddPendingEvent(event
);
625 m_combo
->GetEventHandler()->AddPendingEvent(event
);
637 // ----------------------------------------------------------------------------
639 // ----------------------------------------------------------------------------
642 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
643 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
644 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
645 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
646 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
647 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
648 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
649 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
653 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
655 // Have global double buffer - should be enough for multiple combos
656 static wxBitmap
* gs_doubleBuffer
= (wxBitmap
*) NULL
;
658 void wxComboCtrlBase::Init()
660 m_winPopup
= (wxWindow
*)NULL
;
661 m_popup
= (wxWindow
*)NULL
;
662 m_isPopupShown
= false;
663 m_btn
= (wxWindow
*) NULL
;
664 m_text
= (wxTextCtrl
*) NULL
;
665 m_popupInterface
= (wxComboPopup
*) NULL
;
667 m_extraEvtHandler
= (wxEvtHandler
*) NULL
;
668 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
669 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
671 #if INSTALL_TOPLEV_HANDLER
672 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
676 m_widthMinPopup
= -1;
678 m_widthCustomPaint
= 0;
679 m_widthCustomBorder
= 0;
683 m_blankButtonBg
= false;
684 m_btnWid
= m_btnHei
= -1;
692 m_downReceived
= false;
693 m_timeCanAcceptClick
= 0;
696 bool wxComboCtrlBase::Create(wxWindow
*parent
,
698 const wxString
& value
,
702 const wxValidator
& validator
,
703 const wxString
& name
)
705 if ( !wxControl::Create(parent
,
709 style
| wxWANTS_CHARS
,
714 m_valueString
= value
;
718 m_absIndent
= GetNativeTextIndent();
720 m_iFlags
|= wxCC_IFLAG_CREATED
;
722 // If x and y indicate valid size, wxSizeEvent won't be
723 // emitted automatically, so we need to add artifical one.
724 if ( size
.x
> 0 && size
.y
> 0 )
726 wxSizeEvent
evt(size
,GetId());
727 GetEventHandler()->AddPendingEvent(evt
);
733 void wxComboCtrlBase::InstallInputHandlers( bool alsoTextCtrl
)
735 if ( m_text
&& alsoTextCtrl
)
737 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
738 m_text
->PushEventHandler(m_textEvtHandler
);
741 wxComboBoxExtraInputHandler
* inputHandler
= new wxComboBoxExtraInputHandler(this);
742 PushEventHandler(inputHandler
);
743 m_extraEvtHandler
= inputHandler
;
747 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
749 if ( !(m_windowStyle
& wxCB_READONLY
) )
751 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
752 // not used by the wxPropertyGrid and therefore the tab is processed by
753 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
754 // navigation event is then sent to the wrong window.
755 style
|= wxTE_PROCESS_TAB
;
757 if ( HasFlag(wxTE_PROCESS_ENTER
) )
758 style
|= wxTE_PROCESS_ENTER
;
760 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
761 wxDefaultPosition
, wxDefaultSize
,
764 // This is required for some platforms (GTK+ atleast)
765 m_text
->SetSizeHints(2,4);
769 void wxComboCtrlBase::OnThemeChange()
771 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
774 wxComboCtrlBase::~wxComboCtrlBase()
779 delete gs_doubleBuffer
;
780 gs_doubleBuffer
= (wxBitmap
*) NULL
;
782 #if INSTALL_TOPLEV_HANDLER
783 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
784 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
789 RemoveEventHandler(m_extraEvtHandler
);
792 m_text
->RemoveEventHandler(m_textEvtHandler
);
794 delete m_textEvtHandler
;
795 delete m_extraEvtHandler
;
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 // Recalculates button and textctrl areas
804 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
806 wxSize sz
= GetClientSize();
807 int customBorder
= m_widthCustomBorder
;
808 int btnBorder
; // border for button only
810 // check if button should really be outside the border: we'll do it it if
811 // its platform default or bitmap+pushbutton background is used, but not if
812 // there is vertical size adjustment or horizontal spacing.
813 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
814 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
815 m_btnSpacingX
== 0 &&
818 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
823 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
824 btnBorder
= customBorder
;
827 // Defaul indentation
828 if ( m_absIndent
< 0 )
829 m_absIndent
= GetNativeTextIndent();
831 int butWidth
= btnWidth
;
834 butWidth
= m_btnWidDefault
;
836 m_btnWidDefault
= butWidth
;
841 int butHeight
= sz
.y
- btnBorder
*2;
843 // Adjust button width
848 // Adjust button width to match aspect ratio
849 // (but only if control is smaller than best size).
850 int bestHeight
= GetBestSize().y
;
851 int height
= GetSize().y
;
853 if ( height
< bestHeight
)
855 // Make very small buttons square, as it makes
856 // them accommodate arrow image better and still
859 butWidth
= (height
*butWidth
)/bestHeight
;
861 butWidth
= butHeight
;
865 // Adjust button height
867 butHeight
= m_btnHei
;
869 // Use size of normal bitmap if...
872 // button width is set to default and blank button bg is not drawn
873 if ( m_bmpNormal
.Ok() )
875 int bmpReqWidth
= m_bmpNormal
.GetWidth();
876 int bmpReqHeight
= m_bmpNormal
.GetHeight();
878 // If drawing blank button background, we need to add some margin.
879 if ( m_blankButtonBg
)
881 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
882 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
885 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
886 butWidth
= bmpReqWidth
;
887 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
888 butHeight
= bmpReqHeight
;
890 // Need to fix height?
891 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
893 int newY
= butHeight
+(customBorder
*2);
894 SetClientSize(wxDefaultCoord
,newY
);
899 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
901 m_btnSize
.x
= butWidth
;
902 m_btnSize
.y
= butHeight
;
904 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
905 m_btnArea
.y
= btnBorder
;
906 m_btnArea
.width
= butAreaWid
;
907 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
909 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
910 m_tcArea
.y
= customBorder
;
911 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
912 m_tcArea
.height
= sz
.y
- (customBorder
*2);
917 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
918 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
923 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
928 wxSize sz
= GetClientSize();
929 int customBorder
= m_widthCustomBorder
;
931 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
934 int tcSizeY
= m_text
->GetBestSize().y
;
935 int diff
= sz
.y
- tcSizeY
;
936 int y
= textCtrlYAdjust
+ (diff
/2);
938 if ( y
< customBorder
)
941 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
943 m_tcArea
.width
- COMBO_MARGIN
-
944 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
947 // Make sure textctrl doesn't exceed the bottom custom border
948 wxSize tsz
= m_text
->GetSize();
949 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
952 tsz
.y
= tsz
.y
- diff
- 1;
953 m_text
->SetSize(tsz
);
958 m_text
->SetSize( m_tcArea
.x
,
960 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
965 wxSize
wxComboCtrlBase::DoGetBestSize() const
967 wxSize
sizeText(150,0);
970 sizeText
= m_text
->GetBestSize();
972 // TODO: Better method to calculate close-to-native control height.
976 fhei
= (m_font
.GetPointSize()*2) + 5;
977 else if ( wxNORMAL_FONT
->Ok() )
978 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
980 fhei
= sizeText
.y
+ 4;
982 // Need to force height to accomodate bitmap?
983 int btnSizeY
= m_btnSize
.y
;
984 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
987 // Control height doesn't depend on border
990 int border = m_windowStyle & wxBORDER_MASK;
991 if ( border == wxSIMPLE_BORDER )
993 else if ( border == wxNO_BORDER )
994 fhei += (m_widthCustomBorder*2);
1000 // Final adjustments
1005 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
1012 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1017 // defined by actual wxComboCtrls
1023 // ----------------------------------------------------------------------------
1024 // standard operations
1025 // ----------------------------------------------------------------------------
1027 bool wxComboCtrlBase::Enable(bool enable
)
1029 if ( !wxControl::Enable(enable
) )
1033 m_btn
->Enable(enable
);
1035 m_text
->Enable(enable
);
1040 bool wxComboCtrlBase::Show(bool show
)
1042 if ( !wxControl::Show(show
) )
1054 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1056 if ( !wxControl::SetFont(font
) )
1060 m_text
->SetFont(font
);
1066 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1068 wxControl::DoSetToolTip(tooltip
);
1070 // Set tool tip for button and text box
1073 const wxString
&tip
= tooltip
->GetTip();
1074 if ( m_text
) m_text
->SetToolTip(tip
);
1075 if ( m_btn
) m_btn
->SetToolTip(tip
);
1079 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1080 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1083 #endif // wxUSE_TOOLTIPS
1085 // ----------------------------------------------------------------------------
1087 // ----------------------------------------------------------------------------
1089 // draw focus background on area in a way typical on platform
1090 void wxComboCtrlBase::DrawFocusBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1092 wxSize sz
= GetClientSize();
1094 bool isFocused
; // also selected
1096 // For smaller size control (and for disabled background) use less spacing
1100 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1103 isEnabled
= IsEnabled();
1104 isFocused
= ShouldDrawFocus();
1106 // Windows-style: for smaller size control (and for disabled background) use less spacing
1107 focusSpacingX
= isEnabled
? 2 : 1;
1108 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1112 // Drawing a list item
1113 isEnabled
= true; // they are never disabled
1114 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1120 // Set the background sub-rectangle for selection, disabled etc
1121 wxRect
selRect(rect
);
1122 selRect
.y
+= focusSpacingY
;
1123 selRect
.height
-= (focusSpacingY
*2);
1127 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1128 wcp
+= m_widthCustomPaint
;
1130 selRect
.x
+= wcp
+ focusSpacingX
;
1131 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1137 // If popup is hidden and this control is focused,
1138 // then draw the focus-indicator (selbgcolor background etc.).
1141 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1142 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1146 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1147 bgCol
= GetBackgroundColour();
1152 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1153 bgCol
= GetBackgroundColour();
1156 dc
.SetBrush( bgCol
);
1158 dc
.DrawRectangle( selRect
);
1161 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1163 int drawState
= m_btnState
;
1166 if ( m_isPopupShown
)
1167 drawState
|= wxCONTROL_PRESSED
;
1170 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1171 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1175 // Make sure area is not larger than the control
1176 if ( drawRect
.y
< rect
.y
)
1177 drawRect
.y
= rect
.y
;
1178 if ( drawRect
.height
> rect
.height
)
1179 drawRect
.height
= rect
.height
;
1181 bool enabled
= IsEnabled();
1184 drawState
|= wxCONTROL_DISABLED
;
1186 if ( !m_bmpNormal
.Ok() )
1188 // Need to clear button background even if m_btn is present
1193 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1194 bgCol
= GetParent()->GetBackgroundColour();
1196 bgCol
= GetBackgroundColour();
1200 dc
.DrawRectangle(rect
);
1203 // Draw standard button
1204 wxRendererNative::Get().DrawComboBoxDropButton(this,
1216 pBmp
= &m_bmpDisabled
;
1217 else if ( m_btnState
& wxCONTROL_PRESSED
)
1218 pBmp
= &m_bmpPressed
;
1219 else if ( m_btnState
& wxCONTROL_CURRENT
)
1222 pBmp
= &m_bmpNormal
;
1224 if ( m_blankButtonBg
)
1226 // If using blank button background, we need to clear its background
1227 // with button face colour instead of colour for rest of the control.
1230 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1231 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1234 dc
.DrawRectangle(rect
);
1237 wxRendererNative::Get().DrawPushButton(this,
1246 // Need to clear button background even if m_btn is present
1247 // (assume non-button background was cleared just before this call so brushes are good)
1249 dc
.DrawRectangle(rect
);
1252 // Draw bitmap centered in drawRect
1253 dc
.DrawBitmap(*pBmp
,
1254 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1255 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1260 void wxComboCtrlBase::RecalcAndRefresh()
1264 wxSizeEvent
evt(GetSize(),GetId());
1265 GetEventHandler()->ProcessEvent(evt
);
1270 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1272 // If size is larger, recalculate double buffer bitmap
1273 if ( !gs_doubleBuffer
||
1274 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1275 sz
.y
> gs_doubleBuffer
->GetHeight() )
1277 delete gs_doubleBuffer
;
1278 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1280 return *gs_doubleBuffer
;
1283 // ----------------------------------------------------------------------------
1284 // miscellaneous event handlers
1285 // ----------------------------------------------------------------------------
1287 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1289 // Change event id, object and string before relaying it forward
1290 event
.SetId(GetId());
1291 wxString s
= event
.GetString();
1292 event
.SetEventObject(this);
1297 // call if cursor is on button area or mouse is captured for the button
1298 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1301 int type
= event
.GetEventType();
1303 if ( type
== wxEVT_MOTION
)
1305 if ( flags
& wxCC_MF_ON_BUTTON
)
1307 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1309 // Mouse hover begins
1310 m_btnState
|= wxCONTROL_CURRENT
;
1311 if ( HasCapture() ) // Retain pressed state.
1312 m_btnState
|= wxCONTROL_PRESSED
;
1316 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1319 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1323 else if ( type
== wxEVT_LEFT_DOWN
)
1325 // Only accept event if it wasn't right after popup dismiss
1326 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1328 // Need to test this, because it might be outside.
1329 if ( flags
& wxCC_MF_ON_BUTTON
)
1331 m_btnState
|= wxCONTROL_PRESSED
;
1334 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1337 // If showing popup now, do not capture mouse or there will be interference
1346 else if ( type
== wxEVT_LEFT_UP
)
1349 // Only accept event if mouse was left-press was previously accepted
1353 if ( m_btnState
& wxCONTROL_PRESSED
)
1355 // If mouse was inside, fire the click event.
1356 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1358 if ( flags
& wxCC_MF_ON_BUTTON
)
1362 m_btnState
&= ~(wxCONTROL_PRESSED
);
1366 else if ( type
== wxEVT_LEAVE_WINDOW
)
1368 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1370 m_btnState
&= ~(wxCONTROL_CURRENT
);
1373 if ( !m_isPopupShown
)
1375 m_btnState
&= ~(wxCONTROL_PRESSED
);
1386 // Conversion to double-clicks and some basic filtering
1387 // returns true if event was consumed or filtered
1388 //bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
1389 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1392 wxLongLong t
= ::wxGetLocalTimeMillis();
1393 int evtType
= event
.GetEventType();
1396 // Generate our own double-clicks
1397 // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
1398 if ( (m_windowStyle
& wxCC_SPECIAL_DCLICK
) &&
1400 //!(handlerFlags & wxCC_MF_ON_BUTTON) )
1401 !(flags
& wxCC_MF_ON_BUTTON
) )
1403 if ( evtType
== wxEVT_LEFT_DOWN
)
1405 // Set value to avoid up-events without corresponding downs
1406 m_downReceived
= true;
1408 else if ( evtType
== wxEVT_LEFT_DCLICK
)
1410 // We'll make our own double-clicks
1412 event
.SetEventType(0);
1415 else if ( evtType
== wxEVT_LEFT_UP
)
1417 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
1419 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
1421 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
1423 //type = wxEVT_LEFT_DCLICK;
1424 event
.SetEventType(wxEVT_LEFT_DCLICK
);
1425 m_timeLastMouseUp
= 1;
1429 m_timeLastMouseUp
= t
;
1432 //m_downReceived = false;
1437 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1438 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1440 event
.SetEventType(0);
1447 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1449 int evtType
= event
.GetEventType();
1451 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1452 (m_windowStyle
& wxCB_READONLY
) )
1454 if ( m_isPopupShown
)
1457 // Normally do nothing - evt handler should close it for us
1458 #elif !USE_TRANSIENT_POPUP
1459 // Click here always hides the popup.
1465 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1467 // In read-only mode, clicking the text is the
1468 // same as clicking the button.
1471 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1473 //if ( m_popupInterface->CycleValue() )
1475 if ( m_popupInterface
)
1476 m_popupInterface
->OnComboDoubleClick();
1481 if ( m_isPopupShown
)
1483 // relay (some) mouse events to the popup
1484 if ( evtType
== wxEVT_MOUSEWHEEL
)
1485 m_popup
->AddPendingEvent(event
);
1491 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& )
1493 // First click is the first part of double-click
1494 // Some platforms don't generate down-less mouse up-event
1495 // (Windows does, GTK+2 doesn't), so that's why we have
1497 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
1504 // no need to check for m_widthCustomPaint - that
1505 // area never gets special handling when selected
1506 // (in writable mode, that is)
1510 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1513 // indentation may also have changed
1514 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1515 m_absIndent
= GetNativeTextIndent();
1519 // ----------------------------------------------------------------------------
1521 // ----------------------------------------------------------------------------
1523 // Create popup window and the child control
1524 void wxComboCtrlBase::CreatePopup()
1526 wxComboPopup
* popupInterface
= m_popupInterface
;
1530 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1532 popupInterface
->Create(m_winPopup
);
1533 m_popup
= popup
= popupInterface
->GetControl();
1535 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1536 popup
->PushEventHandler( m_popupExtraHandler
);
1538 // This may be helpful on some platforms
1539 // (eg. it bypasses a wxGTK popupwindow bug where
1540 // window is not initially hidden when it should be)
1543 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1546 // Destroy popup window and the child control
1547 void wxComboCtrlBase::DestroyPopup()
1550 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1552 delete m_popupExtraHandler
;
1556 delete m_popupInterface
;
1559 m_winPopup
->Destroy();
1561 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1562 m_popupInterface
= (wxComboPopup
*) NULL
;
1563 m_winPopup
= (wxWindow
*) NULL
;
1564 m_popup
= (wxWindow
*) NULL
;
1567 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1569 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1573 iface
->InitBase(this);
1576 m_popupInterface
= iface
;
1578 if ( !iface
->LazyCreate() )
1584 m_popup
= (wxWindow
*) NULL
;
1587 // This must be done after creation
1588 if ( m_valueString
.length() )
1590 iface
->SetStringValue(m_valueString
);
1595 // Ensures there is atleast the default popup
1596 void wxComboCtrlBase::EnsurePopupControl()
1598 if ( !m_popupInterface
)
1599 SetPopupControl(NULL
);
1602 void wxComboCtrlBase::OnButtonClick()
1604 // Derived classes can override this method for totally custom
1609 void wxComboCtrlBase::ShowPopup()
1611 EnsurePopupControl();
1612 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1616 // Space above and below
1622 wxSize ctrlSz
= GetSize();
1624 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1625 scrPos
= GetParent()->ClientToScreen(GetPosition());
1627 spaceAbove
= scrPos
.y
;
1628 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1630 maxHeightPopup
= spaceBelow
;
1631 if ( spaceAbove
> spaceBelow
)
1632 maxHeightPopup
= spaceAbove
;
1635 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1637 if ( widthPopup
< m_widthMinPopup
)
1638 widthPopup
= m_widthMinPopup
;
1640 wxWindow
* winPopup
= m_winPopup
;
1643 // Need to disable tab traversal of parent
1645 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1646 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1647 // that if transient popup is open, then tab traversal is to be ignored.
1648 // However, I think this code would still be needed for cases where
1649 // transient popup doesn't work yet (wxWinCE?).
1650 wxWindow
* parent
= GetParent();
1651 int parentFlags
= parent
->GetWindowStyle();
1652 if ( parentFlags
& wxTAB_TRAVERSAL
)
1654 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1655 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1661 winPopup
= m_winPopup
;
1669 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1671 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1672 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1675 popup
->SetSize(adjustedSize
);
1677 m_popupInterface
->OnPopup();
1680 // Reposition and resize popup window
1683 wxSize szp
= popup
->GetSize();
1686 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1688 // Default anchor is wxLEFT
1689 int anchorSide
= m_anchorSide
;
1691 anchorSide
= wxLEFT
;
1693 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1694 int leftX
= scrPos
.x
- m_extLeft
;
1695 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1697 // If there is not enough horizontal space, anchor on the other side.
1698 // If there is no space even then, place the popup at x 0.
1699 if ( anchorSide
== wxRIGHT
)
1703 if ( (leftX
+szp
.x
) < screenWidth
)
1704 anchorSide
= wxLEFT
;
1711 if ( (leftX
+szp
.x
) >= screenWidth
)
1714 anchorSide
= wxRIGHT
;
1720 // Select x coordinate according to the anchor side
1721 if ( anchorSide
== wxRIGHT
)
1723 else if ( anchorSide
== wxLEFT
)
1728 if ( spaceBelow
< szp
.y
)
1730 popupY
= scrPos
.y
- szp
.y
;
1734 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1735 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1737 // Some platforms (GTK) may need these two to be separate
1738 winPopup
->SetSize( szp
.x
, szp
.y
);
1739 winPopup
->Move( popupX
, popupY
);
1741 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1745 // Set string selection (must be this way instead of SetStringSelection)
1748 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1749 m_text
->SelectAll();
1751 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1755 // This is neede since focus/selection indication may change when popup is shown
1759 // This must be after SetStringValue
1760 m_isPopupShown
= true;
1763 #if USE_TRANSIENT_POPUP
1764 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1769 #if INSTALL_TOPLEV_HANDLER
1770 // Put top level window event handler into place
1771 if ( !m_toplevEvtHandler
)
1772 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1774 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1776 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1777 toplev
->PushEventHandler( m_toplevEvtHandler
);
1782 void wxComboCtrlBase::OnPopupDismiss()
1784 // Just in case, avoid double dismiss
1785 if ( !m_isPopupShown
)
1788 // *Must* set this before focus etc.
1789 m_isPopupShown
= false;
1791 // Inform popup control itself
1792 m_popupInterface
->OnDismiss();
1794 if ( m_popupExtraHandler
)
1795 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1797 #if INSTALL_TOPLEV_HANDLER
1798 // Remove top level window event handler
1799 if ( m_toplevEvtHandler
)
1801 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1803 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1807 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1809 // If cursor not on dropdown button, then clear its state
1810 // (technically not required by all ports, but do it for all just in case)
1811 if ( !m_btnArea
.Inside(ScreenToClient(::wxGetMousePosition())) )
1814 // Return parent's tab traversal flag.
1815 // See ShowPopup for notes.
1816 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1818 wxWindow
* parent
= GetParent();
1819 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1820 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1823 // refresh control (necessary even if m_text)
1832 void wxComboCtrlBase::HidePopup()
1834 // Should be able to call this without popup interface
1835 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1836 if ( !m_isPopupShown
)
1839 // transfer value and show it in textctrl, if any
1840 SetValue( m_popupInterface
->GetStringValue() );
1842 #if USE_TRANSIENT_POPUP
1843 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1851 // ----------------------------------------------------------------------------
1852 // customization methods
1853 // ----------------------------------------------------------------------------
1855 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1856 int side
, int spacingX
)
1861 m_btnSpacingX
= spacingX
;
1866 wxSize
wxComboCtrlBase::GetButtonSize()
1868 if ( m_btnSize
.x
> 0 )
1871 wxSize
retSize(m_btnWid
,m_btnHei
);
1873 // Need to call CalculateAreas now if button size is
1874 // is not explicitly specified.
1875 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1879 retSize
= m_btnSize
;
1885 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1887 const wxBitmap
& bmpPressed
,
1888 const wxBitmap
& bmpHover
,
1889 const wxBitmap
& bmpDisabled
)
1891 m_bmpNormal
= bmpNormal
;
1892 m_blankButtonBg
= blankButtonBg
;
1894 if ( bmpPressed
.Ok() )
1895 m_bmpPressed
= bmpPressed
;
1897 m_bmpPressed
= bmpNormal
;
1899 if ( bmpHover
.Ok() )
1900 m_bmpHover
= bmpHover
;
1902 m_bmpHover
= bmpNormal
;
1904 if ( bmpDisabled
.Ok() )
1905 m_bmpDisabled
= bmpDisabled
;
1907 m_bmpDisabled
= bmpNormal
;
1912 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1916 // move textctrl accordingly
1917 wxRect r
= m_text
->GetRect();
1918 int inc
= width
- m_widthCustomPaint
;
1921 m_text
->SetSize( r
);
1924 m_widthCustomPaint
= width
;
1929 void wxComboCtrlBase::SetTextIndent( int indent
)
1933 m_absIndent
= GetNativeTextIndent();
1934 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1938 m_absIndent
= indent
;
1939 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1945 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1947 return DEFAULT_TEXT_INDENT
;
1950 // ----------------------------------------------------------------------------
1951 // methods forwarded to wxTextCtrl
1952 // ----------------------------------------------------------------------------
1954 wxString
wxComboCtrlBase::GetValue() const
1957 return m_text
->GetValue();
1958 return m_valueString
;
1961 void wxComboCtrlBase::SetValue(const wxString
& value
)
1965 m_text
->SetValue(value
);
1966 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1967 m_text
->SelectAll();
1970 m_valueString
= value
;
1974 // Since wxComboPopup may want to paint the combo as well, we need
1975 // to set the string value here (as well as sometimes in ShowPopup).
1976 if ( m_valueString
!= value
&& m_popupInterface
)
1978 m_popupInterface
->SetStringValue(value
);
1982 // In this SetValue variant wxComboPopup::SetStringValue is not called
1983 void wxComboCtrlBase::SetText(const wxString
& value
)
1985 // Unlike in SetValue(), this must be called here or
1986 // the behaviour will no be consistent in readonlys.
1987 EnsurePopupControl();
1989 m_valueString
= value
;
1994 void wxComboCtrlBase::Copy()
2000 void wxComboCtrlBase::Cut()
2006 void wxComboCtrlBase::Paste()
2012 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2015 m_text
->SetInsertionPoint(pos
);
2018 void wxComboCtrlBase::SetInsertionPointEnd()
2021 m_text
->SetInsertionPointEnd();
2024 long wxComboCtrlBase::GetInsertionPoint() const
2027 return m_text
->GetInsertionPoint();
2032 long wxComboCtrlBase::GetLastPosition() const
2035 return m_text
->GetLastPosition();
2040 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2043 m_text
->Replace(from
, to
, value
);
2046 void wxComboCtrlBase::Remove(long from
, long to
)
2049 m_text
->Remove(from
, to
);
2052 void wxComboCtrlBase::SetSelection(long from
, long to
)
2055 m_text
->SetSelection(from
, to
);
2058 void wxComboCtrlBase::Undo()
2064 #endif // wxUSE_COMBOCTRL