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)
65 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
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)
73 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
75 #elif defined(__WXMAC__)
77 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
78 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
82 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
83 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
88 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
89 // what the wxUSE_POPUPWIN says.
90 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
91 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
93 #define wxUSE_POPUPWIN 0
98 #include "wx/popupwin.h"
100 #undef USE_TRANSIENT_POPUP
101 #define USE_TRANSIENT_POPUP 0
105 #if USE_TRANSIENT_POPUP
107 #define wxComboPopupWindowBase wxPopupTransientWindow
108 #define INSTALL_TOPLEV_HANDLER 0
112 #define wxComboPopupWindowBase wxPopupWindow
113 #define INSTALL_TOPLEV_HANDLER 1
117 #define wxComboPopupWindowBase wxDialog
118 #define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
126 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
130 // ----------------------------------------------------------------------------
131 // wxComboFrameEventHandler takes care of hiding the popup when events happen
132 // in its top level parent.
133 // ----------------------------------------------------------------------------
135 #if INSTALL_TOPLEV_HANDLER
138 // This will no longer be necessary after wxTransientPopupWindow
139 // works well on all platforms.
142 class wxComboFrameEventHandler
: public wxEvtHandler
145 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
146 virtual ~wxComboFrameEventHandler();
150 void OnIdle( wxIdleEvent
& event
);
151 void OnMouseEvent( wxMouseEvent
& event
);
152 void OnActivate( wxActivateEvent
& event
);
153 void OnResize( wxSizeEvent
& event
);
154 void OnMove( wxMoveEvent
& event
);
155 void OnMenuEvent( wxMenuEvent
& event
);
156 void OnClose( wxCloseEvent
& event
);
159 wxWindow
* m_focusStart
;
160 wxComboCtrlBase
* m_combo
;
163 DECLARE_EVENT_TABLE()
166 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
167 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
168 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
169 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
170 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
171 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
172 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
173 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
174 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
175 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
178 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
184 wxComboFrameEventHandler::~wxComboFrameEventHandler()
188 void wxComboFrameEventHandler::OnPopup()
190 m_focusStart
= ::wxWindow::FindFocus();
193 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
195 wxWindow
* winFocused
= ::wxWindow::FindFocus();
197 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
198 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
201 winFocused
!= m_focusStart
&&
202 winFocused
!= popup
&&
203 winFocused
->GetParent() != popup
&&
204 winFocused
!= winpopup
&&
205 winFocused
->GetParent() != winpopup
&&
206 winFocused
!= m_combo
&&
207 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
210 m_combo
->HidePopup();
216 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
218 m_combo
->HidePopup();
222 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
224 m_combo
->HidePopup();
228 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
230 m_combo
->HidePopup();
234 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
236 m_combo
->HidePopup();
240 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
242 m_combo
->HidePopup();
246 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
248 m_combo
->HidePopup();
252 #endif // INSTALL_TOPLEV_HANDLER
254 // ----------------------------------------------------------------------------
255 // wxComboPopupWindow is wxPopupWindow customized for
257 // ----------------------------------------------------------------------------
259 class wxComboPopupWindow
: public wxComboPopupWindowBase
263 wxComboPopupWindow( wxComboCtrlBase
*parent
, int style
= wxBORDER_NONE
);
265 #if USE_TRANSIENT_POPUP
266 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
269 void OnKeyEvent(wxKeyEvent
& event
);
271 void OnMouseEvent( wxMouseEvent
& event
);
273 void OnActivate( wxActivateEvent
& event
);
278 #if USE_TRANSIENT_POPUP
279 virtual void OnDismiss();
283 DECLARE_EVENT_TABLE()
287 BEGIN_EVENT_TABLE(wxComboPopupWindow
, wxComboPopupWindowBase
)
288 EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent
)
290 EVT_ACTIVATE(wxComboPopupWindow::OnActivate
)
292 EVT_KEY_DOWN(wxComboPopupWindow::OnKeyEvent
)
293 EVT_KEY_UP(wxComboPopupWindow::OnKeyEvent
)
297 wxComboPopupWindow::wxComboPopupWindow( wxComboCtrlBase
*parent
,
300 : wxComboPopupWindowBase(parent
,style
)
302 : wxComboPopupWindowBase(parent
,
312 void wxComboPopupWindow::OnKeyEvent( wxKeyEvent
& event
)
314 // Relay keyboard event to the main child controls
315 // (just skipping may just cause the popup to close)
316 wxWindowList children
= GetChildren();
317 wxWindowList::iterator node
= children
.begin();
318 wxWindow
* child
= (wxWindow
*)*node
;
319 child
->AddPendingEvent(event
);
322 void wxComboPopupWindow::OnMouseEvent( wxMouseEvent
& event
)
328 void wxComboPopupWindow::OnActivate( wxActivateEvent
& event
)
330 if ( !event
.GetActive() )
332 // Tell combo control that we are dismissed.
333 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
335 wxASSERT( combo
->IsKindOf(CLASSINFO(wxComboCtrl
)) );
344 #if USE_TRANSIENT_POPUP
345 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
347 return wxComboPopupWindowBase::ProcessLeftDown(event
);
351 #if USE_TRANSIENT_POPUP
352 // First thing that happens when a transient popup closes is that this method gets called.
353 void wxComboPopupWindow::OnDismiss()
355 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
356 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
357 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
359 combo
->OnPopupDismiss();
363 // ----------------------------------------------------------------------------
366 // ----------------------------------------------------------------------------
368 wxComboPopup::~wxComboPopup()
372 void wxComboPopup::OnPopup()
376 void wxComboPopup::OnDismiss()
380 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
382 int WXUNUSED(maxHeight
) )
384 return wxSize(minWidth
,prefHeight
);
387 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
388 wxDC
& dc
, const wxRect
& rect
)
390 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
392 combo
->PrepareBackground(dc
,rect
,0);
394 dc
.DrawText( combo
->GetValue(),
395 rect
.x
+ combo
->GetTextIndent(),
396 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
400 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
402 DefaultPaintComboControl(m_combo
,dc
,rect
);
405 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
410 void wxComboPopup::OnComboDoubleClick()
414 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
418 bool wxComboPopup::LazyCreate()
423 void wxComboPopup::Dismiss()
425 m_combo
->HidePopup();
428 // ----------------------------------------------------------------------------
430 // ----------------------------------------------------------------------------
433 // This is pushed to the event handler queue of the child textctrl.
435 class wxComboBoxExtraInputHandler
: public wxEvtHandler
439 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
444 virtual ~wxComboBoxExtraInputHandler() { }
445 void OnKey(wxKeyEvent
& event
);
446 void OnFocus(wxFocusEvent
& event
);
449 wxComboCtrlBase
* m_combo
;
452 DECLARE_EVENT_TABLE()
456 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
457 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
458 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
462 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
464 // Let the wxComboCtrl event handler have a go first.
465 wxComboCtrlBase
* combo
= m_combo
;
466 wxObject
* prevObj
= event
.GetEventObject();
468 event
.SetId(combo
->GetId());
469 event
.SetEventObject(combo
);
470 combo
->GetEventHandler()->ProcessEvent(event
);
472 event
.SetId(((wxWindow
*)prevObj
)->GetId());
473 event
.SetEventObject(prevObj
);
476 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
478 // FIXME: This code does run when control is clicked,
479 // yet on Windows it doesn't select all the text.
480 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
482 if ( m_combo
->GetTextCtrl() )
483 m_combo
->GetTextCtrl()->SelectAll();
485 m_combo
->SetSelection(-1,-1);
488 // Send focus indication to parent.
489 // NB: This is needed for cases where the textctrl gets focus
490 // instead of its parent. While this may trigger multiple
491 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
492 // from combo's focus event handler), they should be quite
494 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
495 evt2
.SetEventObject(m_combo
);
496 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
503 // This is pushed to the event handler queue of the control in popup.
506 class wxComboPopupExtraEventHandler
: public wxEvtHandler
510 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
514 m_beenInside
= false;
516 virtual ~wxComboPopupExtraEventHandler() { }
518 void OnMouseEvent( wxMouseEvent
& event
);
520 // Called from wxComboCtrlBase::OnPopupDismiss
521 void OnPopupDismiss()
523 m_beenInside
= false;
527 wxComboCtrlBase
* m_combo
;
532 DECLARE_EVENT_TABLE()
536 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
537 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
541 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
543 wxPoint pt
= event
.GetPosition();
544 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
545 int evtType
= event
.GetEventType();
546 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
548 if ( evtType
== wxEVT_MOTION
||
549 evtType
== wxEVT_LEFT_DOWN
||
550 evtType
== wxEVT_RIGHT_DOWN
)
552 // Block motion and click events outside the popup
559 else if ( evtType
== wxEVT_LEFT_UP
)
561 // Don't let left-down events in if outside
562 if ( evtType
== wxEVT_LEFT_DOWN
)
577 // Some mouse events to popup that happen outside it, before cursor
578 // has been inside the popu, need to be ignored by it but relayed to
581 wxWindow
* btn
= m_combo
->GetButton();
583 btn
->GetEventHandler()->AddPendingEvent(event
);
585 m_combo
->GetEventHandler()->AddPendingEvent(event
);
597 // ----------------------------------------------------------------------------
599 // ----------------------------------------------------------------------------
602 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
603 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
604 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
605 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
606 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
607 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
608 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
609 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
610 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
614 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
616 void wxComboCtrlBase::Init()
618 m_winPopup
= (wxWindow
*)NULL
;
619 m_popup
= (wxWindow
*)NULL
;
620 m_isPopupShown
= false;
621 m_btn
= (wxWindow
*) NULL
;
622 m_text
= (wxTextCtrl
*) NULL
;
623 m_popupInterface
= (wxComboPopup
*) NULL
;
625 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
626 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
628 #if INSTALL_TOPLEV_HANDLER
629 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
633 m_widthMinPopup
= -1;
635 m_widthCustomPaint
= 0;
636 m_widthCustomBorder
= 0;
640 m_blankButtonBg
= false;
642 m_btnWid
= m_btnHei
= -1;
650 m_timeCanAcceptClick
= 0;
653 bool wxComboCtrlBase::Create(wxWindow
*parent
,
655 const wxString
& value
,
659 const wxValidator
& validator
,
660 const wxString
& name
)
662 if ( !wxControl::Create(parent
,
666 style
| wxWANTS_CHARS
,
671 m_valueString
= value
;
675 m_absIndent
= GetNativeTextIndent();
677 m_iFlags
|= wxCC_IFLAG_CREATED
;
679 // If x and y indicate valid size, wxSizeEvent won't be
680 // emitted automatically, so we need to add artifical one.
681 if ( size
.x
> 0 && size
.y
> 0 )
683 wxSizeEvent
evt(size
,GetId());
684 GetEventHandler()->AddPendingEvent(evt
);
690 void wxComboCtrlBase::InstallInputHandlers()
694 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
695 m_text
->PushEventHandler(m_textEvtHandler
);
700 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
702 if ( !(m_windowStyle
& wxCB_READONLY
) )
707 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
708 // not used by the wxPropertyGrid and therefore the tab is processed by
709 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
710 // navigation event is then sent to the wrong window.
711 style
|= wxTE_PROCESS_TAB
;
713 if ( HasFlag(wxTE_PROCESS_ENTER
) )
714 style
|= wxTE_PROCESS_ENTER
;
716 // Ignore EVT_TEXT generated by the constructor (but only
717 // if the event redirector already exists)
718 // NB: This must be " = 1" instead of "++";
719 if ( m_textEvtHandler
)
724 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
725 wxDefaultPosition
, wxDefaultSize
,
728 // This is required for some platforms (GTK+ atleast)
729 m_text
->SetSizeHints(2,4);
733 void wxComboCtrlBase::OnThemeChange()
735 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
738 wxComboCtrlBase::~wxComboCtrlBase()
743 #if INSTALL_TOPLEV_HANDLER
744 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
745 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
751 m_text
->RemoveEventHandler(m_textEvtHandler
);
753 delete m_textEvtHandler
;
757 // ----------------------------------------------------------------------------
759 // ----------------------------------------------------------------------------
761 // Recalculates button and textctrl areas
762 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
764 wxSize sz
= GetClientSize();
765 int customBorder
= m_widthCustomBorder
;
766 int btnBorder
; // border for button only
768 // check if button should really be outside the border: we'll do it it if
769 // its platform default or bitmap+pushbutton background is used, but not if
770 // there is vertical size adjustment or horizontal spacing.
771 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
772 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
773 m_btnSpacingX
== 0 &&
776 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
781 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
782 btnBorder
= customBorder
;
785 // Defaul indentation
786 if ( m_absIndent
< 0 )
787 m_absIndent
= GetNativeTextIndent();
789 int butWidth
= btnWidth
;
792 butWidth
= m_btnWidDefault
;
794 m_btnWidDefault
= butWidth
;
799 int butHeight
= sz
.y
- btnBorder
*2;
801 // Adjust button width
806 // Adjust button width to match aspect ratio
807 // (but only if control is smaller than best size).
808 int bestHeight
= GetBestSize().y
;
809 int height
= GetSize().y
;
811 if ( height
< bestHeight
)
813 // Make very small buttons square, as it makes
814 // them accommodate arrow image better and still
817 butWidth
= (height
*butWidth
)/bestHeight
;
819 butWidth
= butHeight
;
823 // Adjust button height
825 butHeight
= m_btnHei
;
827 // Use size of normal bitmap if...
830 // button width is set to default and blank button bg is not drawn
831 if ( m_bmpNormal
.Ok() )
833 int bmpReqWidth
= m_bmpNormal
.GetWidth();
834 int bmpReqHeight
= m_bmpNormal
.GetHeight();
836 // If drawing blank button background, we need to add some margin.
837 if ( m_blankButtonBg
)
839 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
840 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
843 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
844 butWidth
= bmpReqWidth
;
845 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
846 butHeight
= bmpReqHeight
;
848 // Need to fix height?
849 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
851 int newY
= butHeight
+(customBorder
*2);
852 SetClientSize(wxDefaultCoord
,newY
);
857 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
859 m_btnSize
.x
= butWidth
;
860 m_btnSize
.y
= butHeight
;
862 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
863 m_btnArea
.y
= btnBorder
;
864 m_btnArea
.width
= butAreaWid
;
865 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
867 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
868 m_tcArea
.y
= customBorder
;
869 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
870 m_tcArea
.height
= sz
.y
- (customBorder
*2);
875 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
876 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
881 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
886 wxSize sz
= GetClientSize();
887 int customBorder
= m_widthCustomBorder
;
889 #if !TEXTCTRL_TEXT_CENTERED
890 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
893 int tcSizeY
= m_text
->GetBestSize().y
;
894 int diff
= sz
.y
- tcSizeY
;
895 int y
= textCtrlYAdjust
+ (diff
/2);
897 if ( y
< customBorder
)
900 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
902 m_tcArea
.width
- COMBO_MARGIN
-
903 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
906 // Make sure textctrl doesn't exceed the bottom custom border
907 wxSize tsz
= m_text
->GetSize();
908 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
911 tsz
.y
= tsz
.y
- diff
- 1;
912 m_text
->SetSize(tsz
);
918 // If it has border, have textctrl will the entire text field.
919 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
921 sz
.x
- m_btnArea
.width
- m_widthCustomPaint
- customBorder
,
922 sz
.y
-(customBorder
*2) );
926 wxSize
wxComboCtrlBase::DoGetBestSize() const
928 wxSize
sizeText(150,0);
931 sizeText
= m_text
->GetBestSize();
933 // TODO: Better method to calculate close-to-native control height.
937 fhei
= (m_font
.GetPointSize()*2) + 5;
938 else if ( wxNORMAL_FONT
->Ok() )
939 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
941 fhei
= sizeText
.y
+ 4;
943 // Need to force height to accomodate bitmap?
944 int btnSizeY
= m_btnSize
.y
;
945 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
948 // Control height doesn't depend on border
951 int border = m_windowStyle & wxBORDER_MASK;
952 if ( border == wxSIMPLE_BORDER )
954 else if ( border == wxNO_BORDER )
955 fhei += (m_widthCustomBorder*2);
966 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
973 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
978 // defined by actual wxComboCtrls
984 // ----------------------------------------------------------------------------
985 // standard operations
986 // ----------------------------------------------------------------------------
988 bool wxComboCtrlBase::Enable(bool enable
)
990 if ( !wxControl::Enable(enable
) )
994 m_btn
->Enable(enable
);
996 m_text
->Enable(enable
);
1001 bool wxComboCtrlBase::Show(bool show
)
1003 if ( !wxControl::Show(show
) )
1015 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1017 if ( !wxControl::SetFont(font
) )
1021 m_text
->SetFont(font
);
1027 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1029 wxControl::DoSetToolTip(tooltip
);
1031 // Set tool tip for button and text box
1034 const wxString
&tip
= tooltip
->GetTip();
1035 if ( m_text
) m_text
->SetToolTip(tip
);
1036 if ( m_btn
) m_btn
->SetToolTip(tip
);
1040 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1041 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1044 #endif // wxUSE_TOOLTIPS
1046 // ----------------------------------------------------------------------------
1048 // ----------------------------------------------------------------------------
1050 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1051 // prepare combo box background on area in a way typical on platform
1052 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1054 wxSize sz
= GetClientSize();
1056 bool isFocused
; // also selected
1058 // For smaller size control (and for disabled background) use less spacing
1062 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1065 isEnabled
= IsEnabled();
1066 isFocused
= ShouldDrawFocus();
1068 // Windows-style: for smaller size control (and for disabled background) use less spacing
1069 focusSpacingX
= isEnabled
? 2 : 1;
1070 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1074 // Drawing a list item
1075 isEnabled
= true; // they are never disabled
1076 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1082 // Set the background sub-rectangle for selection, disabled etc
1083 wxRect
selRect(rect
);
1084 selRect
.y
+= focusSpacingY
;
1085 selRect
.height
-= (focusSpacingY
*2);
1089 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1090 wcp
+= m_widthCustomPaint
;
1092 selRect
.x
+= wcp
+ focusSpacingX
;
1093 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1099 // If popup is hidden and this control is focused,
1100 // then draw the focus-indicator (selbgcolor background etc.).
1103 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1104 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1108 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1109 bgCol
= GetBackgroundColour();
1114 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1115 bgCol
= GetBackgroundColour();
1118 dc
.SetBrush( bgCol
);
1120 dc
.DrawRectangle( selRect
);
1122 // Don't clip exactly to the selection rectangle so we can draw
1123 // to the non-selected area in front of it.
1124 wxRect
clipRect(rect
.x
,rect
.y
,
1125 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1126 dc
.SetClippingRegion(clipRect
);
1129 // Save the library size a bit for platforms that re-implement this.
1130 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1135 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1137 int drawState
= m_btnState
;
1140 if ( m_isPopupShown
)
1141 drawState
|= wxCONTROL_PRESSED
;
1144 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1145 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1149 // Make sure area is not larger than the control
1150 if ( drawRect
.y
< rect
.y
)
1151 drawRect
.y
= rect
.y
;
1152 if ( drawRect
.height
> rect
.height
)
1153 drawRect
.height
= rect
.height
;
1155 bool enabled
= IsEnabled();
1158 drawState
|= wxCONTROL_DISABLED
;
1160 if ( !m_bmpNormal
.Ok() )
1162 // Need to clear button background even if m_btn is present
1167 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1168 bgCol
= GetParent()->GetBackgroundColour();
1170 bgCol
= GetBackgroundColour();
1174 dc
.DrawRectangle(rect
);
1177 // Draw standard button
1178 wxRendererNative::Get().DrawComboBoxDropButton(this,
1190 pBmp
= &m_bmpDisabled
;
1191 else if ( m_btnState
& wxCONTROL_PRESSED
)
1192 pBmp
= &m_bmpPressed
;
1193 else if ( m_btnState
& wxCONTROL_CURRENT
)
1196 pBmp
= &m_bmpNormal
;
1198 if ( m_blankButtonBg
)
1200 // If using blank button background, we need to clear its background
1201 // with button face colour instead of colour for rest of the control.
1204 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1205 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1208 dc
.DrawRectangle(rect
);
1211 wxRendererNative::Get().DrawPushButton(this,
1220 // Need to clear button background even if m_btn is present
1221 // (assume non-button background was cleared just before this call so brushes are good)
1223 dc
.DrawRectangle(rect
);
1226 // Draw bitmap centered in drawRect
1227 dc
.DrawBitmap(*pBmp
,
1228 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1229 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1234 void wxComboCtrlBase::RecalcAndRefresh()
1238 wxSizeEvent
evt(GetSize(),GetId());
1239 GetEventHandler()->ProcessEvent(evt
);
1244 // ----------------------------------------------------------------------------
1245 // miscellaneous event handlers
1246 // ----------------------------------------------------------------------------
1248 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1250 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1252 if ( m_ignoreEvtText
> 0 )
1259 // Change event id, object and string before relaying it forward
1260 event
.SetId(GetId());
1261 wxString s
= event
.GetString();
1262 event
.SetEventObject(this);
1267 // call if cursor is on button area or mouse is captured for the button
1268 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1271 int type
= event
.GetEventType();
1273 if ( type
== wxEVT_MOTION
)
1275 if ( flags
& wxCC_MF_ON_BUTTON
)
1277 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1279 // Mouse hover begins
1280 m_btnState
|= wxCONTROL_CURRENT
;
1281 if ( HasCapture() ) // Retain pressed state.
1282 m_btnState
|= wxCONTROL_PRESSED
;
1286 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1289 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1293 else if ( type
== wxEVT_LEFT_DOWN
)
1295 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1297 m_btnState
|= wxCONTROL_PRESSED
;
1300 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1303 // If showing popup now, do not capture mouse or there will be interference
1307 else if ( type
== wxEVT_LEFT_UP
)
1310 // Only accept event if mouse was left-press was previously accepted
1314 if ( m_btnState
& wxCONTROL_PRESSED
)
1316 // If mouse was inside, fire the click event.
1317 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1319 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1323 m_btnState
&= ~(wxCONTROL_PRESSED
);
1327 else if ( type
== wxEVT_LEAVE_WINDOW
)
1329 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1331 m_btnState
&= ~(wxCONTROL_CURRENT
);
1334 if ( !m_isPopupShown
)
1336 m_btnState
&= ~(wxCONTROL_PRESSED
);
1347 // returns true if event was consumed or filtered
1348 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1349 int WXUNUSED(flags
) )
1351 wxLongLong t
= ::wxGetLocalTimeMillis();
1352 int evtType
= event
.GetEventType();
1354 #if !USE_TRANSIENT_POPUP
1355 if ( m_isPopupShown
&&
1356 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1363 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1364 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1366 event
.SetEventType(0);
1373 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1375 int evtType
= event
.GetEventType();
1377 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1378 (m_windowStyle
& wxCB_READONLY
) )
1380 if ( m_isPopupShown
)
1383 // Normally do nothing - evt handler should close it for us
1384 #elif !USE_TRANSIENT_POPUP
1385 // Click here always hides the popup.
1391 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1393 // In read-only mode, clicking the text is the
1394 // same as clicking the button.
1397 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1399 //if ( m_popupInterface->CycleValue() )
1401 if ( m_popupInterface
)
1402 m_popupInterface
->OnComboDoubleClick();
1407 if ( m_isPopupShown
)
1409 // relay (some) mouse events to the popup
1410 if ( evtType
== wxEVT_MOUSEWHEEL
)
1411 m_popup
->AddPendingEvent(event
);
1417 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1419 if ( IsPopupShown() )
1421 // pass it to the popped up control
1422 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1426 int keycode
= event
.GetKeyCode();
1428 if ( keycode
== WXK_TAB
)
1430 wxNavigationKeyEvent evt
;
1431 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1432 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1433 : wxNavigationKeyEvent::IsBackward
));
1434 evt
.SetEventObject(this);
1435 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1439 if ( IsKeyPopupToggle(event
) )
1445 int comboStyle
= GetWindowStyle();
1446 wxComboPopup
* popupInterface
= GetPopupControl();
1448 if ( !popupInterface
)
1454 if ( (comboStyle
& wxCB_READONLY
) ||
1455 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1457 popupInterface
->OnComboKeyEvent(event
);
1464 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1466 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1468 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1475 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1478 // indentation may also have changed
1479 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1480 m_absIndent
= GetNativeTextIndent();
1484 // ----------------------------------------------------------------------------
1486 // ----------------------------------------------------------------------------
1488 // Create popup window and the child control
1489 void wxComboCtrlBase::CreatePopup()
1491 wxComboPopup
* popupInterface
= m_popupInterface
;
1495 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1497 popupInterface
->Create(m_winPopup
);
1498 m_popup
= popup
= popupInterface
->GetControl();
1500 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1501 popup
->PushEventHandler( m_popupExtraHandler
);
1503 // This may be helpful on some platforms
1504 // (eg. it bypasses a wxGTK popupwindow bug where
1505 // window is not initially hidden when it should be)
1508 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1511 // Destroy popup window and the child control
1512 void wxComboCtrlBase::DestroyPopup()
1517 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1519 delete m_popupExtraHandler
;
1521 delete m_popupInterface
;
1524 m_winPopup
->Destroy();
1526 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1527 m_popupInterface
= (wxComboPopup
*) NULL
;
1528 m_winPopup
= (wxWindow
*) NULL
;
1529 m_popup
= (wxWindow
*) NULL
;
1532 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1534 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1538 iface
->InitBase(this);
1541 m_popupInterface
= iface
;
1543 if ( !iface
->LazyCreate() )
1549 m_popup
= (wxWindow
*) NULL
;
1552 // This must be done after creation
1553 if ( m_valueString
.length() )
1555 iface
->SetStringValue(m_valueString
);
1560 // Ensures there is atleast the default popup
1561 void wxComboCtrlBase::EnsurePopupControl()
1563 if ( !m_popupInterface
)
1564 SetPopupControl(NULL
);
1567 void wxComboCtrlBase::OnButtonClick()
1569 // Derived classes can override this method for totally custom
1574 void wxComboCtrlBase::ShowPopup()
1576 EnsurePopupControl();
1577 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1581 // Space above and below
1587 wxSize ctrlSz
= GetSize();
1589 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1590 scrPos
= GetParent()->ClientToScreen(GetPosition());
1592 spaceAbove
= scrPos
.y
;
1593 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1595 maxHeightPopup
= spaceBelow
;
1596 if ( spaceAbove
> spaceBelow
)
1597 maxHeightPopup
= spaceAbove
;
1600 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1602 if ( widthPopup
< m_widthMinPopup
)
1603 widthPopup
= m_widthMinPopup
;
1605 wxWindow
* winPopup
= m_winPopup
;
1608 // Need to disable tab traversal of parent
1610 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1611 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1612 // that if transient popup is open, then tab traversal is to be ignored.
1613 // However, I think this code would still be needed for cases where
1614 // transient popup doesn't work yet (wxWinCE?).
1615 wxWindow
* parent
= GetParent();
1616 int parentFlags
= parent
->GetWindowStyle();
1617 if ( parentFlags
& wxTAB_TRAVERSAL
)
1619 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1620 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1626 winPopup
= m_winPopup
;
1634 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1636 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1637 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1640 popup
->SetSize(adjustedSize
);
1642 m_popupInterface
->OnPopup();
1645 // Reposition and resize popup window
1648 wxSize szp
= popup
->GetSize();
1651 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1653 // Default anchor is wxLEFT
1654 int anchorSide
= m_anchorSide
;
1656 anchorSide
= wxLEFT
;
1658 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1659 int leftX
= scrPos
.x
- m_extLeft
;
1660 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1662 // If there is not enough horizontal space, anchor on the other side.
1663 // If there is no space even then, place the popup at x 0.
1664 if ( anchorSide
== wxRIGHT
)
1668 if ( (leftX
+szp
.x
) < screenWidth
)
1669 anchorSide
= wxLEFT
;
1676 if ( (leftX
+szp
.x
) >= screenWidth
)
1679 anchorSide
= wxRIGHT
;
1685 // Select x coordinate according to the anchor side
1686 if ( anchorSide
== wxRIGHT
)
1688 else if ( anchorSide
== wxLEFT
)
1693 if ( spaceBelow
< szp
.y
)
1695 popupY
= scrPos
.y
- szp
.y
;
1699 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1700 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1702 // Some platforms (GTK) may need these two to be separate
1703 winPopup
->SetSize( szp
.x
, szp
.y
);
1704 winPopup
->Move( popupX
, popupY
);
1706 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1710 // Set string selection (must be this way instead of SetStringSelection)
1713 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1714 m_text
->SelectAll();
1716 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1720 // This is neede since focus/selection indication may change when popup is shown
1724 // This must be after SetStringValue
1725 m_isPopupShown
= true;
1728 #if USE_TRANSIENT_POPUP
1729 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1734 #if INSTALL_TOPLEV_HANDLER
1735 // Put top level window event handler into place
1736 if ( !m_toplevEvtHandler
)
1737 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1739 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1741 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1742 toplev
->PushEventHandler( m_toplevEvtHandler
);
1747 void wxComboCtrlBase::OnPopupDismiss()
1749 // Just in case, avoid double dismiss
1750 if ( !m_isPopupShown
)
1753 // *Must* set this before focus etc.
1754 m_isPopupShown
= false;
1756 // Inform popup control itself
1757 m_popupInterface
->OnDismiss();
1759 if ( m_popupExtraHandler
)
1760 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1762 #if INSTALL_TOPLEV_HANDLER
1763 // Remove top level window event handler
1764 if ( m_toplevEvtHandler
)
1766 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1768 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1772 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1774 // If cursor not on dropdown button, then clear its state
1775 // (technically not required by all ports, but do it for all just in case)
1776 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1779 // Return parent's tab traversal flag.
1780 // See ShowPopup for notes.
1781 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1783 wxWindow
* parent
= GetParent();
1784 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1785 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1788 // refresh control (necessary even if m_text)
1797 void wxComboCtrlBase::HidePopup()
1799 // Should be able to call this without popup interface
1800 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1801 if ( !m_isPopupShown
)
1804 // transfer value and show it in textctrl, if any
1805 SetValue( m_popupInterface
->GetStringValue() );
1807 #if USE_TRANSIENT_POPUP
1808 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1816 // ----------------------------------------------------------------------------
1817 // customization methods
1818 // ----------------------------------------------------------------------------
1820 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1821 int side
, int spacingX
)
1826 m_btnSpacingX
= spacingX
;
1831 wxSize
wxComboCtrlBase::GetButtonSize()
1833 if ( m_btnSize
.x
> 0 )
1836 wxSize
retSize(m_btnWid
,m_btnHei
);
1838 // Need to call CalculateAreas now if button size is
1839 // is not explicitly specified.
1840 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1844 retSize
= m_btnSize
;
1850 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1852 const wxBitmap
& bmpPressed
,
1853 const wxBitmap
& bmpHover
,
1854 const wxBitmap
& bmpDisabled
)
1856 m_bmpNormal
= bmpNormal
;
1857 m_blankButtonBg
= blankButtonBg
;
1859 if ( bmpPressed
.Ok() )
1860 m_bmpPressed
= bmpPressed
;
1862 m_bmpPressed
= bmpNormal
;
1864 if ( bmpHover
.Ok() )
1865 m_bmpHover
= bmpHover
;
1867 m_bmpHover
= bmpNormal
;
1869 if ( bmpDisabled
.Ok() )
1870 m_bmpDisabled
= bmpDisabled
;
1872 m_bmpDisabled
= bmpNormal
;
1877 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1881 // move textctrl accordingly
1882 wxRect r
= m_text
->GetRect();
1883 int inc
= width
- m_widthCustomPaint
;
1886 m_text
->SetSize( r
);
1889 m_widthCustomPaint
= width
;
1894 void wxComboCtrlBase::SetTextIndent( int indent
)
1898 m_absIndent
= GetNativeTextIndent();
1899 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1903 m_absIndent
= indent
;
1904 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1910 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1912 return DEFAULT_TEXT_INDENT
;
1915 // ----------------------------------------------------------------------------
1916 // methods forwarded to wxTextCtrl
1917 // ----------------------------------------------------------------------------
1919 wxString
wxComboCtrlBase::GetValue() const
1922 return m_text
->GetValue();
1923 return m_valueString
;
1926 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
1933 m_text
->SetValue(value
);
1934 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1935 m_text
->SelectAll();
1938 m_valueString
= value
;
1942 // Since wxComboPopup may want to paint the combo as well, we need
1943 // to set the string value here (as well as sometimes in ShowPopup).
1944 if ( m_valueString
!= value
&& m_popupInterface
)
1946 m_popupInterface
->SetStringValue(value
);
1950 void wxComboCtrlBase::SetValue(const wxString
& value
)
1952 SetValueWithEvent(value
, false);
1955 // In this SetValue variant wxComboPopup::SetStringValue is not called
1956 void wxComboCtrlBase::SetText(const wxString
& value
)
1958 // Unlike in SetValue(), this must be called here or
1959 // the behaviour will no be consistent in readonlys.
1960 EnsurePopupControl();
1962 m_valueString
= value
;
1967 m_text
->SetValue( value
);
1973 void wxComboCtrlBase::Copy()
1979 void wxComboCtrlBase::Cut()
1985 void wxComboCtrlBase::Paste()
1991 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1994 m_text
->SetInsertionPoint(pos
);
1997 void wxComboCtrlBase::SetInsertionPointEnd()
2000 m_text
->SetInsertionPointEnd();
2003 long wxComboCtrlBase::GetInsertionPoint() const
2006 return m_text
->GetInsertionPoint();
2011 long wxComboCtrlBase::GetLastPosition() const
2014 return m_text
->GetLastPosition();
2019 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2022 m_text
->Replace(from
, to
, value
);
2025 void wxComboCtrlBase::Remove(long from
, long to
)
2028 m_text
->Remove(from
, to
);
2031 void wxComboCtrlBase::SetSelection(long from
, long to
)
2034 m_text
->SetSelection(from
, to
);
2037 void wxComboCtrlBase::Undo()
2043 #endif // wxUSE_COMBOCTRL