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
);
917 wxUnusedVar(textCtrlXAdjust
);
918 wxUnusedVar(textCtrlYAdjust
);
921 // If it has border, have textctrl will the entire text field.
922 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
924 sz
.x
- m_btnArea
.width
- m_widthCustomPaint
- customBorder
,
925 sz
.y
-(customBorder
*2) );
929 wxSize
wxComboCtrlBase::DoGetBestSize() const
931 wxSize
sizeText(150,0);
934 sizeText
= m_text
->GetBestSize();
936 // TODO: Better method to calculate close-to-native control height.
940 fhei
= (m_font
.GetPointSize()*2) + 5;
941 else if ( wxNORMAL_FONT
->Ok() )
942 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
944 fhei
= sizeText
.y
+ 4;
946 // Need to force height to accomodate bitmap?
947 int btnSizeY
= m_btnSize
.y
;
948 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
951 // Control height doesn't depend on border
954 int border = m_windowStyle & wxBORDER_MASK;
955 if ( border == wxSIMPLE_BORDER )
957 else if ( border == wxNO_BORDER )
958 fhei += (m_widthCustomBorder*2);
969 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
976 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
981 // defined by actual wxComboCtrls
987 // ----------------------------------------------------------------------------
988 // standard operations
989 // ----------------------------------------------------------------------------
991 bool wxComboCtrlBase::Enable(bool enable
)
993 if ( !wxControl::Enable(enable
) )
997 m_btn
->Enable(enable
);
999 m_text
->Enable(enable
);
1004 bool wxComboCtrlBase::Show(bool show
)
1006 if ( !wxControl::Show(show
) )
1018 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1020 if ( !wxControl::SetFont(font
) )
1024 m_text
->SetFont(font
);
1030 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1032 wxControl::DoSetToolTip(tooltip
);
1034 // Set tool tip for button and text box
1037 const wxString
&tip
= tooltip
->GetTip();
1038 if ( m_text
) m_text
->SetToolTip(tip
);
1039 if ( m_btn
) m_btn
->SetToolTip(tip
);
1043 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1044 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1047 #endif // wxUSE_TOOLTIPS
1049 // ----------------------------------------------------------------------------
1051 // ----------------------------------------------------------------------------
1053 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1054 // prepare combo box background on area in a way typical on platform
1055 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1057 wxSize sz
= GetClientSize();
1059 bool isFocused
; // also selected
1061 // For smaller size control (and for disabled background) use less spacing
1065 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1068 isEnabled
= IsEnabled();
1069 isFocused
= ShouldDrawFocus();
1071 // Windows-style: for smaller size control (and for disabled background) use less spacing
1072 focusSpacingX
= isEnabled
? 2 : 1;
1073 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1077 // Drawing a list item
1078 isEnabled
= true; // they are never disabled
1079 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1085 // Set the background sub-rectangle for selection, disabled etc
1086 wxRect
selRect(rect
);
1087 selRect
.y
+= focusSpacingY
;
1088 selRect
.height
-= (focusSpacingY
*2);
1092 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1093 wcp
+= m_widthCustomPaint
;
1095 selRect
.x
+= wcp
+ focusSpacingX
;
1096 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1102 // If popup is hidden and this control is focused,
1103 // then draw the focus-indicator (selbgcolor background etc.).
1106 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1107 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1111 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1112 bgCol
= GetBackgroundColour();
1117 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1118 bgCol
= GetBackgroundColour();
1121 dc
.SetBrush( bgCol
);
1123 dc
.DrawRectangle( selRect
);
1125 // Don't clip exactly to the selection rectangle so we can draw
1126 // to the non-selected area in front of it.
1127 wxRect
clipRect(rect
.x
,rect
.y
,
1128 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1129 dc
.SetClippingRegion(clipRect
);
1132 // Save the library size a bit for platforms that re-implement this.
1133 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1138 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1140 int drawState
= m_btnState
;
1143 if ( m_isPopupShown
)
1144 drawState
|= wxCONTROL_PRESSED
;
1147 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1148 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1152 // Make sure area is not larger than the control
1153 if ( drawRect
.y
< rect
.y
)
1154 drawRect
.y
= rect
.y
;
1155 if ( drawRect
.height
> rect
.height
)
1156 drawRect
.height
= rect
.height
;
1158 bool enabled
= IsEnabled();
1161 drawState
|= wxCONTROL_DISABLED
;
1163 if ( !m_bmpNormal
.Ok() )
1165 // Need to clear button background even if m_btn is present
1170 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1171 bgCol
= GetParent()->GetBackgroundColour();
1173 bgCol
= GetBackgroundColour();
1177 dc
.DrawRectangle(rect
);
1180 // Draw standard button
1181 wxRendererNative::Get().DrawComboBoxDropButton(this,
1193 pBmp
= &m_bmpDisabled
;
1194 else if ( m_btnState
& wxCONTROL_PRESSED
)
1195 pBmp
= &m_bmpPressed
;
1196 else if ( m_btnState
& wxCONTROL_CURRENT
)
1199 pBmp
= &m_bmpNormal
;
1201 if ( m_blankButtonBg
)
1203 // If using blank button background, we need to clear its background
1204 // with button face colour instead of colour for rest of the control.
1207 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1208 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1211 dc
.DrawRectangle(rect
);
1214 wxRendererNative::Get().DrawPushButton(this,
1223 // Need to clear button background even if m_btn is present
1224 // (assume non-button background was cleared just before this call so brushes are good)
1226 dc
.DrawRectangle(rect
);
1229 // Draw bitmap centered in drawRect
1230 dc
.DrawBitmap(*pBmp
,
1231 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1232 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1237 void wxComboCtrlBase::RecalcAndRefresh()
1241 wxSizeEvent
evt(GetSize(),GetId());
1242 GetEventHandler()->ProcessEvent(evt
);
1247 // ----------------------------------------------------------------------------
1248 // miscellaneous event handlers
1249 // ----------------------------------------------------------------------------
1251 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1253 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1255 if ( m_ignoreEvtText
> 0 )
1262 // Change event id, object and string before relaying it forward
1263 event
.SetId(GetId());
1264 wxString s
= event
.GetString();
1265 event
.SetEventObject(this);
1270 // call if cursor is on button area or mouse is captured for the button
1271 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1274 int type
= event
.GetEventType();
1276 if ( type
== wxEVT_MOTION
)
1278 if ( flags
& wxCC_MF_ON_BUTTON
)
1280 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1282 // Mouse hover begins
1283 m_btnState
|= wxCONTROL_CURRENT
;
1284 if ( HasCapture() ) // Retain pressed state.
1285 m_btnState
|= wxCONTROL_PRESSED
;
1289 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1292 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1296 else if ( type
== wxEVT_LEFT_DOWN
)
1298 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1300 m_btnState
|= wxCONTROL_PRESSED
;
1303 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1306 // If showing popup now, do not capture mouse or there will be interference
1310 else if ( type
== wxEVT_LEFT_UP
)
1313 // Only accept event if mouse was left-press was previously accepted
1317 if ( m_btnState
& wxCONTROL_PRESSED
)
1319 // If mouse was inside, fire the click event.
1320 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1322 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1326 m_btnState
&= ~(wxCONTROL_PRESSED
);
1330 else if ( type
== wxEVT_LEAVE_WINDOW
)
1332 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1334 m_btnState
&= ~(wxCONTROL_CURRENT
);
1337 if ( !m_isPopupShown
)
1339 m_btnState
&= ~(wxCONTROL_PRESSED
);
1350 // returns true if event was consumed or filtered
1351 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1352 int WXUNUSED(flags
) )
1354 wxLongLong t
= ::wxGetLocalTimeMillis();
1355 int evtType
= event
.GetEventType();
1357 #if !USE_TRANSIENT_POPUP
1358 if ( m_isPopupShown
&&
1359 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1366 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1367 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1369 event
.SetEventType(0);
1376 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1378 int evtType
= event
.GetEventType();
1380 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1381 (m_windowStyle
& wxCB_READONLY
) )
1383 if ( m_isPopupShown
)
1386 // Normally do nothing - evt handler should close it for us
1387 #elif !USE_TRANSIENT_POPUP
1388 // Click here always hides the popup.
1394 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1396 // In read-only mode, clicking the text is the
1397 // same as clicking the button.
1400 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1402 //if ( m_popupInterface->CycleValue() )
1404 if ( m_popupInterface
)
1405 m_popupInterface
->OnComboDoubleClick();
1410 if ( m_isPopupShown
)
1412 // relay (some) mouse events to the popup
1413 if ( evtType
== wxEVT_MOUSEWHEEL
)
1414 m_popup
->AddPendingEvent(event
);
1420 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1422 if ( IsPopupShown() )
1424 // pass it to the popped up control
1425 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1429 int keycode
= event
.GetKeyCode();
1431 if ( keycode
== WXK_TAB
)
1433 wxNavigationKeyEvent evt
;
1434 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1435 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1436 : wxNavigationKeyEvent::IsBackward
));
1437 evt
.SetEventObject(this);
1438 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1442 if ( IsKeyPopupToggle(event
) )
1448 int comboStyle
= GetWindowStyle();
1449 wxComboPopup
* popupInterface
= GetPopupControl();
1451 if ( !popupInterface
)
1457 if ( (comboStyle
& wxCB_READONLY
) ||
1458 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1460 popupInterface
->OnComboKeyEvent(event
);
1467 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1469 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1471 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1478 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1481 // indentation may also have changed
1482 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1483 m_absIndent
= GetNativeTextIndent();
1487 // ----------------------------------------------------------------------------
1489 // ----------------------------------------------------------------------------
1491 // Create popup window and the child control
1492 void wxComboCtrlBase::CreatePopup()
1494 wxComboPopup
* popupInterface
= m_popupInterface
;
1498 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1500 popupInterface
->Create(m_winPopup
);
1501 m_popup
= popup
= popupInterface
->GetControl();
1503 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1504 popup
->PushEventHandler( m_popupExtraHandler
);
1506 // This may be helpful on some platforms
1507 // (eg. it bypasses a wxGTK popupwindow bug where
1508 // window is not initially hidden when it should be)
1511 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1514 // Destroy popup window and the child control
1515 void wxComboCtrlBase::DestroyPopup()
1520 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1522 delete m_popupExtraHandler
;
1524 delete m_popupInterface
;
1527 m_winPopup
->Destroy();
1529 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1530 m_popupInterface
= (wxComboPopup
*) NULL
;
1531 m_winPopup
= (wxWindow
*) NULL
;
1532 m_popup
= (wxWindow
*) NULL
;
1535 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1537 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1541 iface
->InitBase(this);
1544 m_popupInterface
= iface
;
1546 if ( !iface
->LazyCreate() )
1552 m_popup
= (wxWindow
*) NULL
;
1555 // This must be done after creation
1556 if ( m_valueString
.length() )
1558 iface
->SetStringValue(m_valueString
);
1563 // Ensures there is atleast the default popup
1564 void wxComboCtrlBase::EnsurePopupControl()
1566 if ( !m_popupInterface
)
1567 SetPopupControl(NULL
);
1570 void wxComboCtrlBase::OnButtonClick()
1572 // Derived classes can override this method for totally custom
1577 void wxComboCtrlBase::ShowPopup()
1579 EnsurePopupControl();
1580 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1584 // Space above and below
1590 wxSize ctrlSz
= GetSize();
1592 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1593 scrPos
= GetParent()->ClientToScreen(GetPosition());
1595 spaceAbove
= scrPos
.y
;
1596 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1598 maxHeightPopup
= spaceBelow
;
1599 if ( spaceAbove
> spaceBelow
)
1600 maxHeightPopup
= spaceAbove
;
1603 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1605 if ( widthPopup
< m_widthMinPopup
)
1606 widthPopup
= m_widthMinPopup
;
1608 wxWindow
* winPopup
= m_winPopup
;
1611 // Need to disable tab traversal of parent
1613 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1614 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1615 // that if transient popup is open, then tab traversal is to be ignored.
1616 // However, I think this code would still be needed for cases where
1617 // transient popup doesn't work yet (wxWinCE?).
1618 wxWindow
* parent
= GetParent();
1619 int parentFlags
= parent
->GetWindowStyle();
1620 if ( parentFlags
& wxTAB_TRAVERSAL
)
1622 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1623 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1629 winPopup
= m_winPopup
;
1637 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1639 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1640 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1643 popup
->SetSize(adjustedSize
);
1645 m_popupInterface
->OnPopup();
1648 // Reposition and resize popup window
1651 wxSize szp
= popup
->GetSize();
1654 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1656 // Default anchor is wxLEFT
1657 int anchorSide
= m_anchorSide
;
1659 anchorSide
= wxLEFT
;
1661 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1662 int leftX
= scrPos
.x
- m_extLeft
;
1663 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1665 // If there is not enough horizontal space, anchor on the other side.
1666 // If there is no space even then, place the popup at x 0.
1667 if ( anchorSide
== wxRIGHT
)
1671 if ( (leftX
+szp
.x
) < screenWidth
)
1672 anchorSide
= wxLEFT
;
1679 if ( (leftX
+szp
.x
) >= screenWidth
)
1682 anchorSide
= wxRIGHT
;
1688 // Select x coordinate according to the anchor side
1689 if ( anchorSide
== wxRIGHT
)
1691 else if ( anchorSide
== wxLEFT
)
1696 if ( spaceBelow
< szp
.y
)
1698 popupY
= scrPos
.y
- szp
.y
;
1702 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1703 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1705 // Some platforms (GTK) may need these two to be separate
1706 winPopup
->SetSize( szp
.x
, szp
.y
);
1707 winPopup
->Move( popupX
, popupY
);
1709 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1713 // Set string selection (must be this way instead of SetStringSelection)
1716 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1717 m_text
->SelectAll();
1719 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1723 // This is neede since focus/selection indication may change when popup is shown
1727 // This must be after SetStringValue
1728 m_isPopupShown
= true;
1731 #if USE_TRANSIENT_POPUP
1732 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1737 #if INSTALL_TOPLEV_HANDLER
1738 // Put top level window event handler into place
1739 if ( !m_toplevEvtHandler
)
1740 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1742 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1744 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1745 toplev
->PushEventHandler( m_toplevEvtHandler
);
1750 void wxComboCtrlBase::OnPopupDismiss()
1752 // Just in case, avoid double dismiss
1753 if ( !m_isPopupShown
)
1756 // *Must* set this before focus etc.
1757 m_isPopupShown
= false;
1759 // Inform popup control itself
1760 m_popupInterface
->OnDismiss();
1762 if ( m_popupExtraHandler
)
1763 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1765 #if INSTALL_TOPLEV_HANDLER
1766 // Remove top level window event handler
1767 if ( m_toplevEvtHandler
)
1769 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1771 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1775 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1777 // If cursor not on dropdown button, then clear its state
1778 // (technically not required by all ports, but do it for all just in case)
1779 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1782 // Return parent's tab traversal flag.
1783 // See ShowPopup for notes.
1784 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1786 wxWindow
* parent
= GetParent();
1787 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1788 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1791 // refresh control (necessary even if m_text)
1800 void wxComboCtrlBase::HidePopup()
1802 // Should be able to call this without popup interface
1803 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1804 if ( !m_isPopupShown
)
1807 // transfer value and show it in textctrl, if any
1808 SetValue( m_popupInterface
->GetStringValue() );
1810 #if USE_TRANSIENT_POPUP
1811 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1819 // ----------------------------------------------------------------------------
1820 // customization methods
1821 // ----------------------------------------------------------------------------
1823 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1824 int side
, int spacingX
)
1829 m_btnSpacingX
= spacingX
;
1834 wxSize
wxComboCtrlBase::GetButtonSize()
1836 if ( m_btnSize
.x
> 0 )
1839 wxSize
retSize(m_btnWid
,m_btnHei
);
1841 // Need to call CalculateAreas now if button size is
1842 // is not explicitly specified.
1843 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1847 retSize
= m_btnSize
;
1853 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1855 const wxBitmap
& bmpPressed
,
1856 const wxBitmap
& bmpHover
,
1857 const wxBitmap
& bmpDisabled
)
1859 m_bmpNormal
= bmpNormal
;
1860 m_blankButtonBg
= blankButtonBg
;
1862 if ( bmpPressed
.Ok() )
1863 m_bmpPressed
= bmpPressed
;
1865 m_bmpPressed
= bmpNormal
;
1867 if ( bmpHover
.Ok() )
1868 m_bmpHover
= bmpHover
;
1870 m_bmpHover
= bmpNormal
;
1872 if ( bmpDisabled
.Ok() )
1873 m_bmpDisabled
= bmpDisabled
;
1875 m_bmpDisabled
= bmpNormal
;
1880 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1884 // move textctrl accordingly
1885 wxRect r
= m_text
->GetRect();
1886 int inc
= width
- m_widthCustomPaint
;
1889 m_text
->SetSize( r
);
1892 m_widthCustomPaint
= width
;
1897 void wxComboCtrlBase::SetTextIndent( int indent
)
1901 m_absIndent
= GetNativeTextIndent();
1902 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1906 m_absIndent
= indent
;
1907 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1913 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1915 return DEFAULT_TEXT_INDENT
;
1918 // ----------------------------------------------------------------------------
1919 // methods forwarded to wxTextCtrl
1920 // ----------------------------------------------------------------------------
1922 wxString
wxComboCtrlBase::GetValue() const
1925 return m_text
->GetValue();
1926 return m_valueString
;
1929 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
1936 m_text
->SetValue(value
);
1937 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1938 m_text
->SelectAll();
1941 m_valueString
= value
;
1945 // Since wxComboPopup may want to paint the combo as well, we need
1946 // to set the string value here (as well as sometimes in ShowPopup).
1947 if ( m_valueString
!= value
&& m_popupInterface
)
1949 m_popupInterface
->SetStringValue(value
);
1953 void wxComboCtrlBase::SetValue(const wxString
& value
)
1955 SetValueWithEvent(value
, false);
1958 // In this SetValue variant wxComboPopup::SetStringValue is not called
1959 void wxComboCtrlBase::SetText(const wxString
& value
)
1961 // Unlike in SetValue(), this must be called here or
1962 // the behaviour will no be consistent in readonlys.
1963 EnsurePopupControl();
1965 m_valueString
= value
;
1970 m_text
->SetValue( value
);
1976 void wxComboCtrlBase::Copy()
1982 void wxComboCtrlBase::Cut()
1988 void wxComboCtrlBase::Paste()
1994 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1997 m_text
->SetInsertionPoint(pos
);
2000 void wxComboCtrlBase::SetInsertionPointEnd()
2003 m_text
->SetInsertionPointEnd();
2006 long wxComboCtrlBase::GetInsertionPoint() const
2009 return m_text
->GetInsertionPoint();
2014 long wxComboCtrlBase::GetLastPosition() const
2017 return m_text
->GetLastPosition();
2022 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2025 m_text
->Replace(from
, to
, value
);
2028 void wxComboCtrlBase::Remove(long from
, long to
)
2031 m_text
->Remove(from
, to
);
2034 void wxComboCtrlBase::SetSelection(long from
, long to
)
2037 m_text
->SetSelection(from
, to
);
2040 void wxComboCtrlBase::Undo()
2046 #endif // wxUSE_COMBOCTRL