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
) )
703 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
704 // not used by the wxPropertyGrid and therefore the tab is processed by
705 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
706 // navigation event is then sent to the wrong window.
707 style
|= wxTE_PROCESS_TAB
;
709 if ( HasFlag(wxTE_PROCESS_ENTER
) )
710 style
|= wxTE_PROCESS_ENTER
;
712 // Ignore EVT_TEXT generated by the constructor (but only
713 // if the event redirector already exists)
714 // NB: This must be " = 1" instead of "++";
715 if ( m_textEvtHandler
)
720 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
721 wxDefaultPosition
, wxDefaultSize
,
724 // This is required for some platforms (GTK+ atleast)
725 m_text
->SetSizeHints(2,4);
729 void wxComboCtrlBase::OnThemeChange()
731 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
734 wxComboCtrlBase::~wxComboCtrlBase()
739 #if INSTALL_TOPLEV_HANDLER
740 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
741 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
747 m_text
->RemoveEventHandler(m_textEvtHandler
);
749 delete m_textEvtHandler
;
753 // ----------------------------------------------------------------------------
755 // ----------------------------------------------------------------------------
757 // Recalculates button and textctrl areas
758 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
760 wxSize sz
= GetClientSize();
761 int customBorder
= m_widthCustomBorder
;
762 int btnBorder
; // border for button only
764 // check if button should really be outside the border: we'll do it it if
765 // its platform default or bitmap+pushbutton background is used, but not if
766 // there is vertical size adjustment or horizontal spacing.
767 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
768 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
769 m_btnSpacingX
== 0 &&
772 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
777 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
778 btnBorder
= customBorder
;
781 // Defaul indentation
782 if ( m_absIndent
< 0 )
783 m_absIndent
= GetNativeTextIndent();
785 int butWidth
= btnWidth
;
788 butWidth
= m_btnWidDefault
;
790 m_btnWidDefault
= butWidth
;
795 int butHeight
= sz
.y
- btnBorder
*2;
797 // Adjust button width
802 // Adjust button width to match aspect ratio
803 // (but only if control is smaller than best size).
804 int bestHeight
= GetBestSize().y
;
805 int height
= GetSize().y
;
807 if ( height
< bestHeight
)
809 // Make very small buttons square, as it makes
810 // them accommodate arrow image better and still
813 butWidth
= (height
*butWidth
)/bestHeight
;
815 butWidth
= butHeight
;
819 // Adjust button height
821 butHeight
= m_btnHei
;
823 // Use size of normal bitmap if...
826 // button width is set to default and blank button bg is not drawn
827 if ( m_bmpNormal
.Ok() )
829 int bmpReqWidth
= m_bmpNormal
.GetWidth();
830 int bmpReqHeight
= m_bmpNormal
.GetHeight();
832 // If drawing blank button background, we need to add some margin.
833 if ( m_blankButtonBg
)
835 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
836 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
839 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
840 butWidth
= bmpReqWidth
;
841 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
842 butHeight
= bmpReqHeight
;
844 // Need to fix height?
845 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
847 int newY
= butHeight
+(customBorder
*2);
848 SetClientSize(wxDefaultCoord
,newY
);
853 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
855 m_btnSize
.x
= butWidth
;
856 m_btnSize
.y
= butHeight
;
858 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
859 m_btnArea
.y
= btnBorder
;
860 m_btnArea
.width
= butAreaWid
;
861 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
863 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
864 m_tcArea
.y
= customBorder
;
865 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
866 m_tcArea
.height
= sz
.y
- (customBorder
*2);
871 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
872 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
877 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
882 wxSize sz
= GetClientSize();
883 int customBorder
= m_widthCustomBorder
;
885 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
888 int tcSizeY
= m_text
->GetBestSize().y
;
889 int diff
= sz
.y
- tcSizeY
;
890 int y
= textCtrlYAdjust
+ (diff
/2);
892 if ( y
< customBorder
)
895 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
897 m_tcArea
.width
- COMBO_MARGIN
-
898 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
901 // Make sure textctrl doesn't exceed the bottom custom border
902 wxSize tsz
= m_text
->GetSize();
903 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
906 tsz
.y
= tsz
.y
- diff
- 1;
907 m_text
->SetSize(tsz
);
912 // If it has border, have textctrl will the entire text field.
913 m_text
->SetSize( m_tcArea
.x
,
915 sz
.x
- m_btnArea
.width
- m_widthCustomPaint
- customBorder
,
920 wxSize
wxComboCtrlBase::DoGetBestSize() const
922 wxSize
sizeText(150,0);
925 sizeText
= m_text
->GetBestSize();
927 // TODO: Better method to calculate close-to-native control height.
931 fhei
= (m_font
.GetPointSize()*2) + 5;
932 else if ( wxNORMAL_FONT
->Ok() )
933 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
935 fhei
= sizeText
.y
+ 4;
937 // Need to force height to accomodate bitmap?
938 int btnSizeY
= m_btnSize
.y
;
939 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
942 // Control height doesn't depend on border
945 int border = m_windowStyle & wxBORDER_MASK;
946 if ( border == wxSIMPLE_BORDER )
948 else if ( border == wxNO_BORDER )
949 fhei += (m_widthCustomBorder*2);
960 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
967 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
972 // defined by actual wxComboCtrls
978 // ----------------------------------------------------------------------------
979 // standard operations
980 // ----------------------------------------------------------------------------
982 bool wxComboCtrlBase::Enable(bool enable
)
984 if ( !wxControl::Enable(enable
) )
988 m_btn
->Enable(enable
);
990 m_text
->Enable(enable
);
995 bool wxComboCtrlBase::Show(bool show
)
997 if ( !wxControl::Show(show
) )
1009 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1011 if ( !wxControl::SetFont(font
) )
1015 m_text
->SetFont(font
);
1021 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1023 wxControl::DoSetToolTip(tooltip
);
1025 // Set tool tip for button and text box
1028 const wxString
&tip
= tooltip
->GetTip();
1029 if ( m_text
) m_text
->SetToolTip(tip
);
1030 if ( m_btn
) m_btn
->SetToolTip(tip
);
1034 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1035 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1038 #endif // wxUSE_TOOLTIPS
1040 // ----------------------------------------------------------------------------
1042 // ----------------------------------------------------------------------------
1044 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1045 // prepare combo box background on area in a way typical on platform
1046 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1048 wxSize sz
= GetClientSize();
1050 bool isFocused
; // also selected
1052 // For smaller size control (and for disabled background) use less spacing
1056 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1059 isEnabled
= IsEnabled();
1060 isFocused
= ShouldDrawFocus();
1062 // Windows-style: for smaller size control (and for disabled background) use less spacing
1063 focusSpacingX
= isEnabled
? 2 : 1;
1064 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1068 // Drawing a list item
1069 isEnabled
= true; // they are never disabled
1070 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1076 // Set the background sub-rectangle for selection, disabled etc
1077 wxRect
selRect(rect
);
1078 selRect
.y
+= focusSpacingY
;
1079 selRect
.height
-= (focusSpacingY
*2);
1083 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1084 wcp
+= m_widthCustomPaint
;
1086 selRect
.x
+= wcp
+ focusSpacingX
;
1087 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1093 // If popup is hidden and this control is focused,
1094 // then draw the focus-indicator (selbgcolor background etc.).
1097 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1098 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1102 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1103 bgCol
= GetBackgroundColour();
1108 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1109 bgCol
= GetBackgroundColour();
1112 dc
.SetBrush( bgCol
);
1114 dc
.DrawRectangle( selRect
);
1116 // Don't clip exactly to the selection rectangle so we can draw
1117 // to the non-selected area in front of it.
1118 wxRect
clipRect(rect
.x
,rect
.y
,
1119 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1120 dc
.SetClippingRegion(clipRect
);
1123 // Save the library size a bit for platforms that re-implement this.
1124 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1129 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1131 int drawState
= m_btnState
;
1134 if ( m_isPopupShown
)
1135 drawState
|= wxCONTROL_PRESSED
;
1138 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1139 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1143 // Make sure area is not larger than the control
1144 if ( drawRect
.y
< rect
.y
)
1145 drawRect
.y
= rect
.y
;
1146 if ( drawRect
.height
> rect
.height
)
1147 drawRect
.height
= rect
.height
;
1149 bool enabled
= IsEnabled();
1152 drawState
|= wxCONTROL_DISABLED
;
1154 if ( !m_bmpNormal
.Ok() )
1156 // Need to clear button background even if m_btn is present
1161 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1162 bgCol
= GetParent()->GetBackgroundColour();
1164 bgCol
= GetBackgroundColour();
1168 dc
.DrawRectangle(rect
);
1171 // Draw standard button
1172 wxRendererNative::Get().DrawComboBoxDropButton(this,
1184 pBmp
= &m_bmpDisabled
;
1185 else if ( m_btnState
& wxCONTROL_PRESSED
)
1186 pBmp
= &m_bmpPressed
;
1187 else if ( m_btnState
& wxCONTROL_CURRENT
)
1190 pBmp
= &m_bmpNormal
;
1192 if ( m_blankButtonBg
)
1194 // If using blank button background, we need to clear its background
1195 // with button face colour instead of colour for rest of the control.
1198 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1199 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1202 dc
.DrawRectangle(rect
);
1205 wxRendererNative::Get().DrawPushButton(this,
1214 // Need to clear button background even if m_btn is present
1215 // (assume non-button background was cleared just before this call so brushes are good)
1217 dc
.DrawRectangle(rect
);
1220 // Draw bitmap centered in drawRect
1221 dc
.DrawBitmap(*pBmp
,
1222 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1223 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1228 void wxComboCtrlBase::RecalcAndRefresh()
1232 wxSizeEvent
evt(GetSize(),GetId());
1233 GetEventHandler()->ProcessEvent(evt
);
1238 // ----------------------------------------------------------------------------
1239 // miscellaneous event handlers
1240 // ----------------------------------------------------------------------------
1242 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1244 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1246 if ( m_ignoreEvtText
> 0 )
1253 // Change event id, object and string before relaying it forward
1254 event
.SetId(GetId());
1255 wxString s
= event
.GetString();
1256 event
.SetEventObject(this);
1261 // call if cursor is on button area or mouse is captured for the button
1262 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1265 int type
= event
.GetEventType();
1267 if ( type
== wxEVT_MOTION
)
1269 if ( flags
& wxCC_MF_ON_BUTTON
)
1271 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1273 // Mouse hover begins
1274 m_btnState
|= wxCONTROL_CURRENT
;
1275 if ( HasCapture() ) // Retain pressed state.
1276 m_btnState
|= wxCONTROL_PRESSED
;
1280 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1283 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1287 else if ( type
== wxEVT_LEFT_DOWN
)
1289 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1291 m_btnState
|= wxCONTROL_PRESSED
;
1294 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1297 // If showing popup now, do not capture mouse or there will be interference
1301 else if ( type
== wxEVT_LEFT_UP
)
1304 // Only accept event if mouse was left-press was previously accepted
1308 if ( m_btnState
& wxCONTROL_PRESSED
)
1310 // If mouse was inside, fire the click event.
1311 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1313 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1317 m_btnState
&= ~(wxCONTROL_PRESSED
);
1321 else if ( type
== wxEVT_LEAVE_WINDOW
)
1323 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1325 m_btnState
&= ~(wxCONTROL_CURRENT
);
1328 if ( !m_isPopupShown
)
1330 m_btnState
&= ~(wxCONTROL_PRESSED
);
1341 // returns true if event was consumed or filtered
1342 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1343 int WXUNUSED(flags
) )
1345 wxLongLong t
= ::wxGetLocalTimeMillis();
1346 int evtType
= event
.GetEventType();
1348 #if !USE_TRANSIENT_POPUP
1349 if ( m_isPopupShown
&&
1350 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1357 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1358 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1360 event
.SetEventType(0);
1367 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1369 int evtType
= event
.GetEventType();
1371 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1372 (m_windowStyle
& wxCB_READONLY
) )
1374 if ( m_isPopupShown
)
1377 // Normally do nothing - evt handler should close it for us
1378 #elif !USE_TRANSIENT_POPUP
1379 // Click here always hides the popup.
1385 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1387 // In read-only mode, clicking the text is the
1388 // same as clicking the button.
1391 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1393 //if ( m_popupInterface->CycleValue() )
1395 if ( m_popupInterface
)
1396 m_popupInterface
->OnComboDoubleClick();
1401 if ( m_isPopupShown
)
1403 // relay (some) mouse events to the popup
1404 if ( evtType
== wxEVT_MOUSEWHEEL
)
1405 m_popup
->AddPendingEvent(event
);
1411 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1413 if ( IsPopupShown() )
1415 // pass it to the popped up control
1416 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1420 int keycode
= event
.GetKeyCode();
1422 if ( keycode
== WXK_TAB
)
1424 wxNavigationKeyEvent evt
;
1425 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1426 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1427 : wxNavigationKeyEvent::IsBackward
));
1428 evt
.SetEventObject(this);
1429 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1433 if ( IsKeyPopupToggle(event
) )
1439 int comboStyle
= GetWindowStyle();
1440 wxComboPopup
* popupInterface
= GetPopupControl();
1442 if ( !popupInterface
)
1448 if ( (comboStyle
& wxCB_READONLY
) ||
1449 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1451 popupInterface
->OnComboKeyEvent(event
);
1458 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1460 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1462 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1469 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1472 // indentation may also have changed
1473 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1474 m_absIndent
= GetNativeTextIndent();
1478 // ----------------------------------------------------------------------------
1480 // ----------------------------------------------------------------------------
1482 // Create popup window and the child control
1483 void wxComboCtrlBase::CreatePopup()
1485 wxComboPopup
* popupInterface
= m_popupInterface
;
1489 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1491 popupInterface
->Create(m_winPopup
);
1492 m_popup
= popup
= popupInterface
->GetControl();
1494 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1495 popup
->PushEventHandler( m_popupExtraHandler
);
1497 // This may be helpful on some platforms
1498 // (eg. it bypasses a wxGTK popupwindow bug where
1499 // window is not initially hidden when it should be)
1502 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1505 // Destroy popup window and the child control
1506 void wxComboCtrlBase::DestroyPopup()
1511 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1513 delete m_popupExtraHandler
;
1515 delete m_popupInterface
;
1518 m_winPopup
->Destroy();
1520 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1521 m_popupInterface
= (wxComboPopup
*) NULL
;
1522 m_winPopup
= (wxWindow
*) NULL
;
1523 m_popup
= (wxWindow
*) NULL
;
1526 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1528 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1532 iface
->InitBase(this);
1535 m_popupInterface
= iface
;
1537 if ( !iface
->LazyCreate() )
1543 m_popup
= (wxWindow
*) NULL
;
1546 // This must be done after creation
1547 if ( m_valueString
.length() )
1549 iface
->SetStringValue(m_valueString
);
1554 // Ensures there is atleast the default popup
1555 void wxComboCtrlBase::EnsurePopupControl()
1557 if ( !m_popupInterface
)
1558 SetPopupControl(NULL
);
1561 void wxComboCtrlBase::OnButtonClick()
1563 // Derived classes can override this method for totally custom
1568 void wxComboCtrlBase::ShowPopup()
1570 EnsurePopupControl();
1571 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1575 // Space above and below
1581 wxSize ctrlSz
= GetSize();
1583 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1584 scrPos
= GetParent()->ClientToScreen(GetPosition());
1586 spaceAbove
= scrPos
.y
;
1587 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1589 maxHeightPopup
= spaceBelow
;
1590 if ( spaceAbove
> spaceBelow
)
1591 maxHeightPopup
= spaceAbove
;
1594 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1596 if ( widthPopup
< m_widthMinPopup
)
1597 widthPopup
= m_widthMinPopup
;
1599 wxWindow
* winPopup
= m_winPopup
;
1602 // Need to disable tab traversal of parent
1604 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1605 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1606 // that if transient popup is open, then tab traversal is to be ignored.
1607 // However, I think this code would still be needed for cases where
1608 // transient popup doesn't work yet (wxWinCE?).
1609 wxWindow
* parent
= GetParent();
1610 int parentFlags
= parent
->GetWindowStyle();
1611 if ( parentFlags
& wxTAB_TRAVERSAL
)
1613 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1614 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1620 winPopup
= m_winPopup
;
1628 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1630 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1631 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1634 popup
->SetSize(adjustedSize
);
1636 m_popupInterface
->OnPopup();
1639 // Reposition and resize popup window
1642 wxSize szp
= popup
->GetSize();
1645 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1647 // Default anchor is wxLEFT
1648 int anchorSide
= m_anchorSide
;
1650 anchorSide
= wxLEFT
;
1652 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1653 int leftX
= scrPos
.x
- m_extLeft
;
1654 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1656 // If there is not enough horizontal space, anchor on the other side.
1657 // If there is no space even then, place the popup at x 0.
1658 if ( anchorSide
== wxRIGHT
)
1662 if ( (leftX
+szp
.x
) < screenWidth
)
1663 anchorSide
= wxLEFT
;
1670 if ( (leftX
+szp
.x
) >= screenWidth
)
1673 anchorSide
= wxRIGHT
;
1679 // Select x coordinate according to the anchor side
1680 if ( anchorSide
== wxRIGHT
)
1682 else if ( anchorSide
== wxLEFT
)
1687 if ( spaceBelow
< szp
.y
)
1689 popupY
= scrPos
.y
- szp
.y
;
1693 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1694 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1696 // Some platforms (GTK) may need these two to be separate
1697 winPopup
->SetSize( szp
.x
, szp
.y
);
1698 winPopup
->Move( popupX
, popupY
);
1700 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1704 // Set string selection (must be this way instead of SetStringSelection)
1707 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1708 m_text
->SelectAll();
1710 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1714 // This is neede since focus/selection indication may change when popup is shown
1718 // This must be after SetStringValue
1719 m_isPopupShown
= true;
1722 #if USE_TRANSIENT_POPUP
1723 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1728 #if INSTALL_TOPLEV_HANDLER
1729 // Put top level window event handler into place
1730 if ( !m_toplevEvtHandler
)
1731 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1733 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1735 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1736 toplev
->PushEventHandler( m_toplevEvtHandler
);
1741 void wxComboCtrlBase::OnPopupDismiss()
1743 // Just in case, avoid double dismiss
1744 if ( !m_isPopupShown
)
1747 // *Must* set this before focus etc.
1748 m_isPopupShown
= false;
1750 // Inform popup control itself
1751 m_popupInterface
->OnDismiss();
1753 if ( m_popupExtraHandler
)
1754 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1756 #if INSTALL_TOPLEV_HANDLER
1757 // Remove top level window event handler
1758 if ( m_toplevEvtHandler
)
1760 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1762 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1766 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1768 // If cursor not on dropdown button, then clear its state
1769 // (technically not required by all ports, but do it for all just in case)
1770 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1773 // Return parent's tab traversal flag.
1774 // See ShowPopup for notes.
1775 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1777 wxWindow
* parent
= GetParent();
1778 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1779 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1782 // refresh control (necessary even if m_text)
1791 void wxComboCtrlBase::HidePopup()
1793 // Should be able to call this without popup interface
1794 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1795 if ( !m_isPopupShown
)
1798 // transfer value and show it in textctrl, if any
1799 SetValue( m_popupInterface
->GetStringValue() );
1801 #if USE_TRANSIENT_POPUP
1802 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1810 // ----------------------------------------------------------------------------
1811 // customization methods
1812 // ----------------------------------------------------------------------------
1814 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1815 int side
, int spacingX
)
1820 m_btnSpacingX
= spacingX
;
1825 wxSize
wxComboCtrlBase::GetButtonSize()
1827 if ( m_btnSize
.x
> 0 )
1830 wxSize
retSize(m_btnWid
,m_btnHei
);
1832 // Need to call CalculateAreas now if button size is
1833 // is not explicitly specified.
1834 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1838 retSize
= m_btnSize
;
1844 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1846 const wxBitmap
& bmpPressed
,
1847 const wxBitmap
& bmpHover
,
1848 const wxBitmap
& bmpDisabled
)
1850 m_bmpNormal
= bmpNormal
;
1851 m_blankButtonBg
= blankButtonBg
;
1853 if ( bmpPressed
.Ok() )
1854 m_bmpPressed
= bmpPressed
;
1856 m_bmpPressed
= bmpNormal
;
1858 if ( bmpHover
.Ok() )
1859 m_bmpHover
= bmpHover
;
1861 m_bmpHover
= bmpNormal
;
1863 if ( bmpDisabled
.Ok() )
1864 m_bmpDisabled
= bmpDisabled
;
1866 m_bmpDisabled
= bmpNormal
;
1871 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1875 // move textctrl accordingly
1876 wxRect r
= m_text
->GetRect();
1877 int inc
= width
- m_widthCustomPaint
;
1880 m_text
->SetSize( r
);
1883 m_widthCustomPaint
= width
;
1888 void wxComboCtrlBase::SetTextIndent( int indent
)
1892 m_absIndent
= GetNativeTextIndent();
1893 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1897 m_absIndent
= indent
;
1898 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1904 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1906 return DEFAULT_TEXT_INDENT
;
1909 // ----------------------------------------------------------------------------
1910 // methods forwarded to wxTextCtrl
1911 // ----------------------------------------------------------------------------
1913 wxString
wxComboCtrlBase::GetValue() const
1916 return m_text
->GetValue();
1917 return m_valueString
;
1920 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
1927 m_text
->SetValue(value
);
1928 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1929 m_text
->SelectAll();
1932 m_valueString
= value
;
1936 // Since wxComboPopup may want to paint the combo as well, we need
1937 // to set the string value here (as well as sometimes in ShowPopup).
1938 if ( m_valueString
!= value
&& m_popupInterface
)
1940 m_popupInterface
->SetStringValue(value
);
1944 void wxComboCtrlBase::SetValue(const wxString
& value
)
1946 SetValueWithEvent(value
, false);
1949 // In this SetValue variant wxComboPopup::SetStringValue is not called
1950 void wxComboCtrlBase::SetText(const wxString
& value
)
1952 // Unlike in SetValue(), this must be called here or
1953 // the behaviour will no be consistent in readonlys.
1954 EnsurePopupControl();
1956 m_valueString
= value
;
1961 m_text
->SetValue( value
);
1967 void wxComboCtrlBase::Copy()
1973 void wxComboCtrlBase::Cut()
1979 void wxComboCtrlBase::Paste()
1985 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1988 m_text
->SetInsertionPoint(pos
);
1991 void wxComboCtrlBase::SetInsertionPointEnd()
1994 m_text
->SetInsertionPointEnd();
1997 long wxComboCtrlBase::GetInsertionPoint() const
2000 return m_text
->GetInsertionPoint();
2005 long wxComboCtrlBase::GetLastPosition() const
2008 return m_text
->GetLastPosition();
2013 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2016 m_text
->Replace(from
, to
, value
);
2019 void wxComboCtrlBase::Remove(long from
, long to
)
2022 m_text
->Remove(from
, to
);
2025 void wxComboCtrlBase::SetSelection(long from
, long to
)
2028 m_text
->SetSelection(from
, to
);
2031 void wxComboCtrlBase::Undo()
2037 #endif // wxUSE_COMBOCTRL