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/tooltip.h"
45 // ----------------------------------------------------------------------------
47 // Milliseconds to wait for two mouse-ups after focus inorder
48 // to trigger a double-click.
49 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
51 #define DEFAULT_DROPBUTTON_WIDTH 19
53 #define BMP_BUTTON_MARGIN 4
55 #define DEFAULT_POPUP_HEIGHT 400
57 #define DEFAULT_TEXT_INDENT 3
59 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
62 #if defined(__WXMSW__)
64 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
66 //#undef wxUSE_POPUPWIN
67 //#define wxUSE_POPUPWIN 0
69 #elif defined(__WXGTK__)
71 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
73 #elif defined(__WXMAC__)
75 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
79 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
84 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
85 // what the wxUSE_POPUPWIN says.
86 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
87 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
89 #define wxUSE_POPUPWIN 0
94 #include "wx/popupwin.h"
96 #undef USE_TRANSIENT_POPUP
97 #define USE_TRANSIENT_POPUP 0
101 #if USE_TRANSIENT_POPUP
103 #define wxComboPopupWindowBase wxPopupTransientWindow
104 #define INSTALL_TOPLEV_HANDLER 0
108 #define wxComboPopupWindowBase wxPopupWindow
109 #define INSTALL_TOPLEV_HANDLER 1
113 #define wxComboPopupWindowBase wxDialog
114 #define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
122 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
126 // ----------------------------------------------------------------------------
127 // wxComboFrameEventHandler takes care of hiding the popup when events happen
128 // in its top level parent.
129 // ----------------------------------------------------------------------------
131 #if INSTALL_TOPLEV_HANDLER
134 // This will no longer be necessary after wxTransientPopupWindow
135 // works well on all platforms.
138 class wxComboFrameEventHandler
: public wxEvtHandler
141 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
142 virtual ~wxComboFrameEventHandler();
146 void OnIdle( wxIdleEvent
& event
);
147 void OnMouseEvent( wxMouseEvent
& event
);
148 void OnActivate( wxActivateEvent
& event
);
149 void OnResize( wxSizeEvent
& event
);
150 void OnMove( wxMoveEvent
& event
);
151 void OnMenuEvent( wxMenuEvent
& event
);
152 void OnClose( wxCloseEvent
& event
);
155 wxWindow
* m_focusStart
;
156 wxComboCtrlBase
* m_combo
;
159 DECLARE_EVENT_TABLE()
162 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
163 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
164 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
165 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
166 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
167 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
168 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
169 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
170 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
171 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
174 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
180 wxComboFrameEventHandler::~wxComboFrameEventHandler()
184 void wxComboFrameEventHandler::OnPopup()
186 m_focusStart
= ::wxWindow::FindFocus();
189 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
191 wxWindow
* winFocused
= ::wxWindow::FindFocus();
193 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
194 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
197 winFocused
!= m_focusStart
&&
198 winFocused
!= popup
&&
199 winFocused
->GetParent() != popup
&&
200 winFocused
!= winpopup
&&
201 winFocused
->GetParent() != winpopup
&&
202 winFocused
!= m_combo
&&
203 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
206 m_combo
->HidePopup();
212 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
214 m_combo
->HidePopup();
218 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
220 m_combo
->HidePopup();
224 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
226 m_combo
->HidePopup();
230 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
232 m_combo
->HidePopup();
236 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
238 m_combo
->HidePopup();
242 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
244 m_combo
->HidePopup();
248 #endif // INSTALL_TOPLEV_HANDLER
250 // ----------------------------------------------------------------------------
251 // wxComboPopupWindow is wxPopupWindow customized for
253 // ----------------------------------------------------------------------------
255 class wxComboPopupWindow
: public wxComboPopupWindowBase
259 wxComboPopupWindow( wxComboCtrlBase
*parent
, int style
= wxBORDER_NONE
);
261 #if USE_TRANSIENT_POPUP
262 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
265 void OnKeyEvent(wxKeyEvent
& event
);
267 void OnMouseEvent( wxMouseEvent
& event
);
269 void OnActivate( wxActivateEvent
& event
);
274 #if USE_TRANSIENT_POPUP
275 virtual void OnDismiss();
279 DECLARE_EVENT_TABLE()
283 BEGIN_EVENT_TABLE(wxComboPopupWindow
, wxComboPopupWindowBase
)
284 EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent
)
286 EVT_ACTIVATE(wxComboPopupWindow::OnActivate
)
288 EVT_KEY_DOWN(wxComboPopupWindow::OnKeyEvent
)
289 EVT_KEY_UP(wxComboPopupWindow::OnKeyEvent
)
293 wxComboPopupWindow::wxComboPopupWindow( wxComboCtrlBase
*parent
,
296 : wxComboPopupWindowBase(parent
,style
)
298 : wxComboPopupWindowBase(parent
,
308 void wxComboPopupWindow::OnKeyEvent( wxKeyEvent
& event
)
310 // Relay keyboard event to the main child controls
311 // (just skipping may just cause the popup to close)
312 wxWindowList children
= GetChildren();
313 wxWindowList::iterator node
= children
.begin();
314 wxWindow
* child
= (wxWindow
*)*node
;
315 child
->AddPendingEvent(event
);
318 void wxComboPopupWindow::OnMouseEvent( wxMouseEvent
& event
)
324 void wxComboPopupWindow::OnActivate( wxActivateEvent
& event
)
326 if ( !event
.GetActive() )
328 // Tell combo control that we are dismissed.
329 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
331 wxASSERT( combo
->IsKindOf(CLASSINFO(wxComboCtrl
)) );
340 #if USE_TRANSIENT_POPUP
341 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
343 return wxComboPopupWindowBase::ProcessLeftDown(event
);
347 #if USE_TRANSIENT_POPUP
348 // First thing that happens when a transient popup closes is that this method gets called.
349 void wxComboPopupWindow::OnDismiss()
351 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
352 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
353 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
355 combo
->OnPopupDismiss();
359 // ----------------------------------------------------------------------------
362 // ----------------------------------------------------------------------------
364 wxComboPopup::~wxComboPopup()
368 void wxComboPopup::OnPopup()
372 void wxComboPopup::OnDismiss()
376 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
378 int WXUNUSED(maxHeight
) )
380 return wxSize(minWidth
,prefHeight
);
383 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
384 wxDC
& dc
, const wxRect
& rect
)
386 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
388 combo
->PrepareBackground(dc
,rect
,0);
390 dc
.DrawText( combo
->GetValue(),
391 rect
.x
+ combo
->GetTextIndent(),
392 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
396 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
398 DefaultPaintComboControl(m_combo
,dc
,rect
);
401 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
406 void wxComboPopup::OnComboDoubleClick()
410 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
414 bool wxComboPopup::LazyCreate()
419 void wxComboPopup::Dismiss()
421 m_combo
->HidePopup();
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
429 // This is pushed to the event handler queue of the child textctrl.
431 class wxComboBoxExtraInputHandler
: public wxEvtHandler
435 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
440 virtual ~wxComboBoxExtraInputHandler() { }
441 void OnKey(wxKeyEvent
& event
);
442 void OnFocus(wxFocusEvent
& event
);
445 wxComboCtrlBase
* m_combo
;
448 DECLARE_EVENT_TABLE()
452 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
453 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
454 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
458 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
460 // Let the wxComboCtrl event handler have a go first.
461 wxComboCtrlBase
* combo
= m_combo
;
462 wxObject
* prevObj
= event
.GetEventObject();
464 event
.SetId(combo
->GetId());
465 event
.SetEventObject(combo
);
466 combo
->GetEventHandler()->ProcessEvent(event
);
468 event
.SetId(((wxWindow
*)prevObj
)->GetId());
469 event
.SetEventObject(prevObj
);
472 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
474 // FIXME: This code does run when control is clicked,
475 // yet on Windows it doesn't select all the text.
476 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
478 if ( m_combo
->GetTextCtrl() )
479 m_combo
->GetTextCtrl()->SelectAll();
481 m_combo
->SetSelection(-1,-1);
484 // Send focus indication to parent.
485 // NB: This is needed for cases where the textctrl gets focus
486 // instead of its parent. While this may trigger multiple
487 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
488 // from combo's focus event handler), they should be quite
490 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
491 evt2
.SetEventObject(m_combo
);
492 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
499 // This is pushed to the event handler queue of the control in popup.
502 class wxComboPopupExtraEventHandler
: public wxEvtHandler
506 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
510 m_beenInside
= false;
512 virtual ~wxComboPopupExtraEventHandler() { }
514 void OnMouseEvent( wxMouseEvent
& event
);
516 // Called from wxComboCtrlBase::OnPopupDismiss
517 void OnPopupDismiss()
519 m_beenInside
= false;
523 wxComboCtrlBase
* m_combo
;
528 DECLARE_EVENT_TABLE()
532 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
533 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
537 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
539 wxPoint pt
= event
.GetPosition();
540 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
541 int evtType
= event
.GetEventType();
542 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
544 if ( evtType
== wxEVT_MOTION
||
545 evtType
== wxEVT_LEFT_DOWN
||
546 evtType
== wxEVT_RIGHT_DOWN
)
548 // Block motion and click events outside the popup
555 else if ( evtType
== wxEVT_LEFT_UP
)
557 // Don't let left-down events in if outside
558 if ( evtType
== wxEVT_LEFT_DOWN
)
573 // Some mouse events to popup that happen outside it, before cursor
574 // has been inside the popu, need to be ignored by it but relayed to
577 wxWindow
* btn
= m_combo
->GetButton();
579 btn
->GetEventHandler()->AddPendingEvent(event
);
581 m_combo
->GetEventHandler()->AddPendingEvent(event
);
593 // ----------------------------------------------------------------------------
595 // ----------------------------------------------------------------------------
598 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
599 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
600 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
601 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
602 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
603 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
604 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
605 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
606 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
610 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
612 void wxComboCtrlBase::Init()
614 m_winPopup
= (wxWindow
*)NULL
;
615 m_popup
= (wxWindow
*)NULL
;
616 m_isPopupShown
= false;
617 m_btn
= (wxWindow
*) NULL
;
618 m_text
= (wxTextCtrl
*) NULL
;
619 m_popupInterface
= (wxComboPopup
*) NULL
;
621 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
622 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
624 #if INSTALL_TOPLEV_HANDLER
625 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
629 m_widthMinPopup
= -1;
631 m_widthCustomPaint
= 0;
632 m_widthCustomBorder
= 0;
636 m_blankButtonBg
= false;
638 m_btnWid
= m_btnHei
= -1;
646 m_timeCanAcceptClick
= 0;
649 bool wxComboCtrlBase::Create(wxWindow
*parent
,
651 const wxString
& value
,
655 const wxValidator
& validator
,
656 const wxString
& name
)
658 if ( !wxControl::Create(parent
,
662 style
| wxWANTS_CHARS
,
667 m_valueString
= value
;
671 m_absIndent
= GetNativeTextIndent();
673 m_iFlags
|= wxCC_IFLAG_CREATED
;
675 // If x and y indicate valid size, wxSizeEvent won't be
676 // emitted automatically, so we need to add artifical one.
677 if ( size
.x
> 0 && size
.y
> 0 )
679 wxSizeEvent
evt(size
,GetId());
680 GetEventHandler()->AddPendingEvent(evt
);
686 void wxComboCtrlBase::InstallInputHandlers()
690 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
691 m_text
->PushEventHandler(m_textEvtHandler
);
696 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
698 if ( !(m_windowStyle
& wxCB_READONLY
) )
700 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
701 // not used by the wxPropertyGrid and therefore the tab is processed by
702 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
703 // navigation event is then sent to the wrong window.
704 style
|= wxTE_PROCESS_TAB
;
706 if ( HasFlag(wxTE_PROCESS_ENTER
) )
707 style
|= wxTE_PROCESS_ENTER
;
709 // Ignore EVT_TEXT generated by the constructor (but only
710 // if the event redirector already exists)
711 // NB: This must be " = 1" instead of "++";
712 if ( m_textEvtHandler
)
717 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
718 wxDefaultPosition
, wxDefaultSize
,
721 // This is required for some platforms (GTK+ atleast)
722 m_text
->SetSizeHints(2,4);
726 void wxComboCtrlBase::OnThemeChange()
728 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
731 wxComboCtrlBase::~wxComboCtrlBase()
736 #if INSTALL_TOPLEV_HANDLER
737 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
738 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
744 m_text
->RemoveEventHandler(m_textEvtHandler
);
746 delete m_textEvtHandler
;
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
754 // Recalculates button and textctrl areas
755 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
757 wxSize sz
= GetClientSize();
758 int customBorder
= m_widthCustomBorder
;
759 int btnBorder
; // border for button only
761 // check if button should really be outside the border: we'll do it it if
762 // its platform default or bitmap+pushbutton background is used, but not if
763 // there is vertical size adjustment or horizontal spacing.
764 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
765 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
766 m_btnSpacingX
== 0 &&
769 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
774 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
775 btnBorder
= customBorder
;
778 // Defaul indentation
779 if ( m_absIndent
< 0 )
780 m_absIndent
= GetNativeTextIndent();
782 int butWidth
= btnWidth
;
785 butWidth
= m_btnWidDefault
;
787 m_btnWidDefault
= butWidth
;
792 int butHeight
= sz
.y
- btnBorder
*2;
794 // Adjust button width
799 // Adjust button width to match aspect ratio
800 // (but only if control is smaller than best size).
801 int bestHeight
= GetBestSize().y
;
802 int height
= GetSize().y
;
804 if ( height
< bestHeight
)
806 // Make very small buttons square, as it makes
807 // them accommodate arrow image better and still
810 butWidth
= (height
*butWidth
)/bestHeight
;
812 butWidth
= butHeight
;
816 // Adjust button height
818 butHeight
= m_btnHei
;
820 // Use size of normal bitmap if...
823 // button width is set to default and blank button bg is not drawn
824 if ( m_bmpNormal
.Ok() )
826 int bmpReqWidth
= m_bmpNormal
.GetWidth();
827 int bmpReqHeight
= m_bmpNormal
.GetHeight();
829 // If drawing blank button background, we need to add some margin.
830 if ( m_blankButtonBg
)
832 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
833 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
836 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
837 butWidth
= bmpReqWidth
;
838 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
839 butHeight
= bmpReqHeight
;
841 // Need to fix height?
842 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
844 int newY
= butHeight
+(customBorder
*2);
845 SetClientSize(wxDefaultCoord
,newY
);
850 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
852 m_btnSize
.x
= butWidth
;
853 m_btnSize
.y
= butHeight
;
855 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
856 m_btnArea
.y
= btnBorder
;
857 m_btnArea
.width
= butAreaWid
;
858 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
860 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
861 m_tcArea
.y
= customBorder
;
862 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
863 m_tcArea
.height
= sz
.y
- (customBorder
*2);
868 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
869 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
874 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
879 wxSize sz
= GetClientSize();
880 int customBorder
= m_widthCustomBorder
;
882 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
885 int tcSizeY
= m_text
->GetBestSize().y
;
886 int diff
= sz
.y
- tcSizeY
;
887 int y
= textCtrlYAdjust
+ (diff
/2);
889 if ( y
< customBorder
)
892 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
894 m_tcArea
.width
- COMBO_MARGIN
-
895 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
898 // Make sure textctrl doesn't exceed the bottom custom border
899 wxSize tsz
= m_text
->GetSize();
900 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
903 tsz
.y
= tsz
.y
- diff
- 1;
904 m_text
->SetSize(tsz
);
909 m_text
->SetSize( m_tcArea
.x
,
911 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
916 wxSize
wxComboCtrlBase::DoGetBestSize() const
918 wxSize
sizeText(150,0);
921 sizeText
= m_text
->GetBestSize();
923 // TODO: Better method to calculate close-to-native control height.
927 fhei
= (m_font
.GetPointSize()*2) + 5;
928 else if ( wxNORMAL_FONT
->Ok() )
929 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
931 fhei
= sizeText
.y
+ 4;
933 // Need to force height to accomodate bitmap?
934 int btnSizeY
= m_btnSize
.y
;
935 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
938 // Control height doesn't depend on border
941 int border = m_windowStyle & wxBORDER_MASK;
942 if ( border == wxSIMPLE_BORDER )
944 else if ( border == wxNO_BORDER )
945 fhei += (m_widthCustomBorder*2);
956 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
963 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
968 // defined by actual wxComboCtrls
974 // ----------------------------------------------------------------------------
975 // standard operations
976 // ----------------------------------------------------------------------------
978 bool wxComboCtrlBase::Enable(bool enable
)
980 if ( !wxControl::Enable(enable
) )
984 m_btn
->Enable(enable
);
986 m_text
->Enable(enable
);
991 bool wxComboCtrlBase::Show(bool show
)
993 if ( !wxControl::Show(show
) )
1005 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1007 if ( !wxControl::SetFont(font
) )
1011 m_text
->SetFont(font
);
1017 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1019 wxControl::DoSetToolTip(tooltip
);
1021 // Set tool tip for button and text box
1024 const wxString
&tip
= tooltip
->GetTip();
1025 if ( m_text
) m_text
->SetToolTip(tip
);
1026 if ( m_btn
) m_btn
->SetToolTip(tip
);
1030 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1031 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1034 #endif // wxUSE_TOOLTIPS
1036 // ----------------------------------------------------------------------------
1038 // ----------------------------------------------------------------------------
1040 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1041 // prepare combo box background on area in a way typical on platform
1042 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1044 wxSize sz
= GetClientSize();
1046 bool isFocused
; // also selected
1048 // For smaller size control (and for disabled background) use less spacing
1052 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1055 isEnabled
= IsEnabled();
1056 isFocused
= ShouldDrawFocus();
1058 // Windows-style: for smaller size control (and for disabled background) use less spacing
1059 focusSpacingX
= isEnabled
? 2 : 1;
1060 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1064 // Drawing a list item
1065 isEnabled
= true; // they are never disabled
1066 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1072 // Set the background sub-rectangle for selection, disabled etc
1073 wxRect
selRect(rect
);
1074 selRect
.y
+= focusSpacingY
;
1075 selRect
.height
-= (focusSpacingY
*2);
1079 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1080 wcp
+= m_widthCustomPaint
;
1082 selRect
.x
+= wcp
+ focusSpacingX
;
1083 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1089 // If popup is hidden and this control is focused,
1090 // then draw the focus-indicator (selbgcolor background etc.).
1093 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1094 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1098 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1099 bgCol
= GetBackgroundColour();
1104 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1105 bgCol
= GetBackgroundColour();
1108 dc
.SetBrush( bgCol
);
1110 dc
.DrawRectangle( selRect
);
1112 // Don't clip exactly to the selection rectangle so we can draw
1113 // to the non-selected area in front of it.
1114 wxRect
clipRect(rect
.x
,rect
.y
,
1115 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1116 dc
.SetClippingRegion(clipRect
);
1119 // Save the library size a bit for platforms that re-implement this.
1120 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1125 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1127 int drawState
= m_btnState
;
1130 if ( m_isPopupShown
)
1131 drawState
|= wxCONTROL_PRESSED
;
1134 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1135 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1139 // Make sure area is not larger than the control
1140 if ( drawRect
.y
< rect
.y
)
1141 drawRect
.y
= rect
.y
;
1142 if ( drawRect
.height
> rect
.height
)
1143 drawRect
.height
= rect
.height
;
1145 bool enabled
= IsEnabled();
1148 drawState
|= wxCONTROL_DISABLED
;
1150 if ( !m_bmpNormal
.Ok() )
1152 // Need to clear button background even if m_btn is present
1157 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1158 bgCol
= GetParent()->GetBackgroundColour();
1160 bgCol
= GetBackgroundColour();
1164 dc
.DrawRectangle(rect
);
1167 // Draw standard button
1168 wxRendererNative::Get().DrawComboBoxDropButton(this,
1180 pBmp
= &m_bmpDisabled
;
1181 else if ( m_btnState
& wxCONTROL_PRESSED
)
1182 pBmp
= &m_bmpPressed
;
1183 else if ( m_btnState
& wxCONTROL_CURRENT
)
1186 pBmp
= &m_bmpNormal
;
1188 if ( m_blankButtonBg
)
1190 // If using blank button background, we need to clear its background
1191 // with button face colour instead of colour for rest of the control.
1194 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1195 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1198 dc
.DrawRectangle(rect
);
1201 wxRendererNative::Get().DrawPushButton(this,
1210 // Need to clear button background even if m_btn is present
1211 // (assume non-button background was cleared just before this call so brushes are good)
1213 dc
.DrawRectangle(rect
);
1216 // Draw bitmap centered in drawRect
1217 dc
.DrawBitmap(*pBmp
,
1218 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1219 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1224 void wxComboCtrlBase::RecalcAndRefresh()
1228 wxSizeEvent
evt(GetSize(),GetId());
1229 GetEventHandler()->ProcessEvent(evt
);
1234 // ----------------------------------------------------------------------------
1235 // miscellaneous event handlers
1236 // ----------------------------------------------------------------------------
1238 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1240 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1242 if ( m_ignoreEvtText
> 0 )
1249 // Change event id, object and string before relaying it forward
1250 event
.SetId(GetId());
1251 wxString s
= event
.GetString();
1252 event
.SetEventObject(this);
1257 // call if cursor is on button area or mouse is captured for the button
1258 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1261 int type
= event
.GetEventType();
1263 if ( type
== wxEVT_MOTION
)
1265 if ( flags
& wxCC_MF_ON_BUTTON
)
1267 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1269 // Mouse hover begins
1270 m_btnState
|= wxCONTROL_CURRENT
;
1271 if ( HasCapture() ) // Retain pressed state.
1272 m_btnState
|= wxCONTROL_PRESSED
;
1276 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1279 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1283 else if ( type
== wxEVT_LEFT_DOWN
)
1285 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1287 m_btnState
|= wxCONTROL_PRESSED
;
1290 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1293 // If showing popup now, do not capture mouse or there will be interference
1297 else if ( type
== wxEVT_LEFT_UP
)
1300 // Only accept event if mouse was left-press was previously accepted
1304 if ( m_btnState
& wxCONTROL_PRESSED
)
1306 // If mouse was inside, fire the click event.
1307 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1309 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1313 m_btnState
&= ~(wxCONTROL_PRESSED
);
1317 else if ( type
== wxEVT_LEAVE_WINDOW
)
1319 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1321 m_btnState
&= ~(wxCONTROL_CURRENT
);
1324 if ( !m_isPopupShown
)
1326 m_btnState
&= ~(wxCONTROL_PRESSED
);
1337 // returns true if event was consumed or filtered
1338 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1339 int WXUNUSED(flags
) )
1341 wxLongLong t
= ::wxGetLocalTimeMillis();
1342 int evtType
= event
.GetEventType();
1344 #if !USE_TRANSIENT_POPUP
1345 if ( m_isPopupShown
&&
1346 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1353 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1354 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1356 event
.SetEventType(0);
1363 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1365 int evtType
= event
.GetEventType();
1367 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1368 (m_windowStyle
& wxCB_READONLY
) )
1370 if ( m_isPopupShown
)
1373 // Normally do nothing - evt handler should close it for us
1374 #elif !USE_TRANSIENT_POPUP
1375 // Click here always hides the popup.
1381 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1383 // In read-only mode, clicking the text is the
1384 // same as clicking the button.
1387 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1389 //if ( m_popupInterface->CycleValue() )
1391 if ( m_popupInterface
)
1392 m_popupInterface
->OnComboDoubleClick();
1397 if ( m_isPopupShown
)
1399 // relay (some) mouse events to the popup
1400 if ( evtType
== wxEVT_MOUSEWHEEL
)
1401 m_popup
->AddPendingEvent(event
);
1407 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1409 if ( IsPopupShown() )
1411 // pass it to the popped up control
1412 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1416 int keycode
= event
.GetKeyCode();
1418 if ( keycode
== WXK_TAB
)
1420 wxNavigationKeyEvent evt
;
1421 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1422 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1423 : wxNavigationKeyEvent::IsBackward
));
1424 evt
.SetEventObject(this);
1425 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1429 if ( IsKeyPopupToggle(event
) )
1435 int comboStyle
= GetWindowStyle();
1436 wxComboPopup
* popupInterface
= GetPopupControl();
1438 if ( !popupInterface
)
1444 if ( (comboStyle
& wxCB_READONLY
) ||
1445 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1447 popupInterface
->OnComboKeyEvent(event
);
1454 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1456 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1458 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1465 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1468 // indentation may also have changed
1469 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1470 m_absIndent
= GetNativeTextIndent();
1474 // ----------------------------------------------------------------------------
1476 // ----------------------------------------------------------------------------
1478 // Create popup window and the child control
1479 void wxComboCtrlBase::CreatePopup()
1481 wxComboPopup
* popupInterface
= m_popupInterface
;
1485 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1487 popupInterface
->Create(m_winPopup
);
1488 m_popup
= popup
= popupInterface
->GetControl();
1490 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1491 popup
->PushEventHandler( m_popupExtraHandler
);
1493 // This may be helpful on some platforms
1494 // (eg. it bypasses a wxGTK popupwindow bug where
1495 // window is not initially hidden when it should be)
1498 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1501 // Destroy popup window and the child control
1502 void wxComboCtrlBase::DestroyPopup()
1507 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1509 delete m_popupExtraHandler
;
1511 delete m_popupInterface
;
1514 m_winPopup
->Destroy();
1516 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1517 m_popupInterface
= (wxComboPopup
*) NULL
;
1518 m_winPopup
= (wxWindow
*) NULL
;
1519 m_popup
= (wxWindow
*) NULL
;
1522 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1524 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1528 iface
->InitBase(this);
1531 m_popupInterface
= iface
;
1533 if ( !iface
->LazyCreate() )
1539 m_popup
= (wxWindow
*) NULL
;
1542 // This must be done after creation
1543 if ( m_valueString
.length() )
1545 iface
->SetStringValue(m_valueString
);
1550 // Ensures there is atleast the default popup
1551 void wxComboCtrlBase::EnsurePopupControl()
1553 if ( !m_popupInterface
)
1554 SetPopupControl(NULL
);
1557 void wxComboCtrlBase::OnButtonClick()
1559 // Derived classes can override this method for totally custom
1564 void wxComboCtrlBase::ShowPopup()
1566 EnsurePopupControl();
1567 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1571 // Space above and below
1577 wxSize ctrlSz
= GetSize();
1579 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1580 scrPos
= GetParent()->ClientToScreen(GetPosition());
1582 spaceAbove
= scrPos
.y
;
1583 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1585 maxHeightPopup
= spaceBelow
;
1586 if ( spaceAbove
> spaceBelow
)
1587 maxHeightPopup
= spaceAbove
;
1590 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1592 if ( widthPopup
< m_widthMinPopup
)
1593 widthPopup
= m_widthMinPopup
;
1595 wxWindow
* winPopup
= m_winPopup
;
1598 // Need to disable tab traversal of parent
1600 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1601 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1602 // that if transient popup is open, then tab traversal is to be ignored.
1603 // However, I think this code would still be needed for cases where
1604 // transient popup doesn't work yet (wxWinCE?).
1605 wxWindow
* parent
= GetParent();
1606 int parentFlags
= parent
->GetWindowStyle();
1607 if ( parentFlags
& wxTAB_TRAVERSAL
)
1609 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1610 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1616 winPopup
= m_winPopup
;
1624 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1626 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1627 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1630 popup
->SetSize(adjustedSize
);
1632 m_popupInterface
->OnPopup();
1635 // Reposition and resize popup window
1638 wxSize szp
= popup
->GetSize();
1641 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1643 // Default anchor is wxLEFT
1644 int anchorSide
= m_anchorSide
;
1646 anchorSide
= wxLEFT
;
1648 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1649 int leftX
= scrPos
.x
- m_extLeft
;
1650 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1652 // If there is not enough horizontal space, anchor on the other side.
1653 // If there is no space even then, place the popup at x 0.
1654 if ( anchorSide
== wxRIGHT
)
1658 if ( (leftX
+szp
.x
) < screenWidth
)
1659 anchorSide
= wxLEFT
;
1666 if ( (leftX
+szp
.x
) >= screenWidth
)
1669 anchorSide
= wxRIGHT
;
1675 // Select x coordinate according to the anchor side
1676 if ( anchorSide
== wxRIGHT
)
1678 else if ( anchorSide
== wxLEFT
)
1683 if ( spaceBelow
< szp
.y
)
1685 popupY
= scrPos
.y
- szp
.y
;
1689 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1690 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1692 // Some platforms (GTK) may need these two to be separate
1693 winPopup
->SetSize( szp
.x
, szp
.y
);
1694 winPopup
->Move( popupX
, popupY
);
1696 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1700 // Set string selection (must be this way instead of SetStringSelection)
1703 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1704 m_text
->SelectAll();
1706 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1710 // This is neede since focus/selection indication may change when popup is shown
1714 // This must be after SetStringValue
1715 m_isPopupShown
= true;
1718 #if USE_TRANSIENT_POPUP
1719 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1724 #if INSTALL_TOPLEV_HANDLER
1725 // Put top level window event handler into place
1726 if ( !m_toplevEvtHandler
)
1727 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1729 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1731 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1732 toplev
->PushEventHandler( m_toplevEvtHandler
);
1737 void wxComboCtrlBase::OnPopupDismiss()
1739 // Just in case, avoid double dismiss
1740 if ( !m_isPopupShown
)
1743 // *Must* set this before focus etc.
1744 m_isPopupShown
= false;
1746 // Inform popup control itself
1747 m_popupInterface
->OnDismiss();
1749 if ( m_popupExtraHandler
)
1750 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1752 #if INSTALL_TOPLEV_HANDLER
1753 // Remove top level window event handler
1754 if ( m_toplevEvtHandler
)
1756 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1758 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1762 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1764 // If cursor not on dropdown button, then clear its state
1765 // (technically not required by all ports, but do it for all just in case)
1766 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1769 // Return parent's tab traversal flag.
1770 // See ShowPopup for notes.
1771 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1773 wxWindow
* parent
= GetParent();
1774 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1775 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1778 // refresh control (necessary even if m_text)
1787 void wxComboCtrlBase::HidePopup()
1789 // Should be able to call this without popup interface
1790 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1791 if ( !m_isPopupShown
)
1794 // transfer value and show it in textctrl, if any
1795 SetValue( m_popupInterface
->GetStringValue() );
1797 #if USE_TRANSIENT_POPUP
1798 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1806 // ----------------------------------------------------------------------------
1807 // customization methods
1808 // ----------------------------------------------------------------------------
1810 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1811 int side
, int spacingX
)
1816 m_btnSpacingX
= spacingX
;
1821 wxSize
wxComboCtrlBase::GetButtonSize()
1823 if ( m_btnSize
.x
> 0 )
1826 wxSize
retSize(m_btnWid
,m_btnHei
);
1828 // Need to call CalculateAreas now if button size is
1829 // is not explicitly specified.
1830 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1834 retSize
= m_btnSize
;
1840 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1842 const wxBitmap
& bmpPressed
,
1843 const wxBitmap
& bmpHover
,
1844 const wxBitmap
& bmpDisabled
)
1846 m_bmpNormal
= bmpNormal
;
1847 m_blankButtonBg
= blankButtonBg
;
1849 if ( bmpPressed
.Ok() )
1850 m_bmpPressed
= bmpPressed
;
1852 m_bmpPressed
= bmpNormal
;
1854 if ( bmpHover
.Ok() )
1855 m_bmpHover
= bmpHover
;
1857 m_bmpHover
= bmpNormal
;
1859 if ( bmpDisabled
.Ok() )
1860 m_bmpDisabled
= bmpDisabled
;
1862 m_bmpDisabled
= bmpNormal
;
1867 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1871 // move textctrl accordingly
1872 wxRect r
= m_text
->GetRect();
1873 int inc
= width
- m_widthCustomPaint
;
1876 m_text
->SetSize( r
);
1879 m_widthCustomPaint
= width
;
1884 void wxComboCtrlBase::SetTextIndent( int indent
)
1888 m_absIndent
= GetNativeTextIndent();
1889 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1893 m_absIndent
= indent
;
1894 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1900 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1902 return DEFAULT_TEXT_INDENT
;
1905 // ----------------------------------------------------------------------------
1906 // methods forwarded to wxTextCtrl
1907 // ----------------------------------------------------------------------------
1909 wxString
wxComboCtrlBase::GetValue() const
1912 return m_text
->GetValue();
1913 return m_valueString
;
1916 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
1923 m_text
->SetValue(value
);
1924 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1925 m_text
->SelectAll();
1928 m_valueString
= value
;
1932 // Since wxComboPopup may want to paint the combo as well, we need
1933 // to set the string value here (as well as sometimes in ShowPopup).
1934 if ( m_valueString
!= value
&& m_popupInterface
)
1936 m_popupInterface
->SetStringValue(value
);
1940 void wxComboCtrlBase::SetValue(const wxString
& value
)
1942 SetValueWithEvent(value
, false);
1945 // In this SetValue variant wxComboPopup::SetStringValue is not called
1946 void wxComboCtrlBase::SetText(const wxString
& value
)
1948 // Unlike in SetValue(), this must be called here or
1949 // the behaviour will no be consistent in readonlys.
1950 EnsurePopupControl();
1952 m_valueString
= value
;
1957 m_text
->SetValue( value
);
1963 void wxComboCtrlBase::Copy()
1969 void wxComboCtrlBase::Cut()
1975 void wxComboCtrlBase::Paste()
1981 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1984 m_text
->SetInsertionPoint(pos
);
1987 void wxComboCtrlBase::SetInsertionPointEnd()
1990 m_text
->SetInsertionPointEnd();
1993 long wxComboCtrlBase::GetInsertionPoint() const
1996 return m_text
->GetInsertionPoint();
2001 long wxComboCtrlBase::GetLastPosition() const
2004 return m_text
->GetLastPosition();
2009 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2012 m_text
->Replace(from
, to
, value
);
2015 void wxComboCtrlBase::Remove(long from
, long to
)
2018 m_text
->Remove(from
, to
);
2021 void wxComboCtrlBase::SetSelection(long from
, long to
)
2024 m_text
->SetSelection(from
, to
);
2027 void wxComboCtrlBase::Undo()
2033 #endif // wxUSE_COMBOCTRL