1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/combobox.h"
32 #include "wx/dcclient.h"
33 #include "wx/settings.h"
34 #include "wx/dialog.h"
38 #include "wx/dcbuffer.h"
39 #include "wx/tooltip.h"
46 // ----------------------------------------------------------------------------
48 // Milliseconds to wait for two mouse-ups after focus inorder
49 // to trigger a double-click.
50 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
52 #define DEFAULT_DROPBUTTON_WIDTH 19
54 #define BMP_BUTTON_MARGIN 4
56 #define DEFAULT_POPUP_HEIGHT 400
58 #define DEFAULT_TEXT_INDENT 3
60 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
63 #if defined(__WXMSW__)
65 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
67 //#undef wxUSE_POPUPWIN
68 //#define wxUSE_POPUPWIN 0
70 #elif defined(__WXGTK__)
72 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
74 #elif defined(__WXMAC__)
76 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
80 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
85 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
86 // what the wxUSE_POPUPWIN says.
87 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
88 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
90 #define wxUSE_POPUPWIN 0
95 #include "wx/popupwin.h"
97 #undef USE_TRANSIENT_POPUP
98 #define USE_TRANSIENT_POPUP 0
102 #if USE_TRANSIENT_POPUP
104 #define wxComboPopupWindowBase wxPopupTransientWindow
105 #define INSTALL_TOPLEV_HANDLER 0
109 #define wxComboPopupWindowBase wxPopupWindow
110 #define INSTALL_TOPLEV_HANDLER 1
114 #define wxComboPopupWindowBase wxDialog
115 #define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
123 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
127 // ----------------------------------------------------------------------------
128 // wxComboFrameEventHandler takes care of hiding the popup when events happen
129 // in its top level parent.
130 // ----------------------------------------------------------------------------
132 #if INSTALL_TOPLEV_HANDLER
135 // This will no longer be necessary after wxTransientPopupWindow
136 // works well on all platforms.
139 class wxComboFrameEventHandler
: public wxEvtHandler
142 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
143 virtual ~wxComboFrameEventHandler();
147 void OnIdle( wxIdleEvent
& event
);
148 void OnMouseEvent( wxMouseEvent
& event
);
149 void OnActivate( wxActivateEvent
& event
);
150 void OnResize( wxSizeEvent
& event
);
151 void OnMove( wxMoveEvent
& event
);
152 void OnMenuEvent( wxMenuEvent
& event
);
153 void OnClose( wxCloseEvent
& event
);
156 wxWindow
* m_focusStart
;
157 wxComboCtrlBase
* m_combo
;
160 DECLARE_EVENT_TABLE()
163 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
164 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
165 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
166 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
167 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
168 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
169 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
170 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
171 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
172 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
175 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
181 wxComboFrameEventHandler::~wxComboFrameEventHandler()
185 void wxComboFrameEventHandler::OnPopup()
187 m_focusStart
= ::wxWindow::FindFocus();
190 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
192 wxWindow
* winFocused
= ::wxWindow::FindFocus();
194 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
195 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
198 winFocused
!= m_focusStart
&&
199 winFocused
!= popup
&&
200 winFocused
->GetParent() != popup
&&
201 winFocused
!= winpopup
&&
202 winFocused
->GetParent() != winpopup
&&
203 winFocused
!= m_combo
&&
204 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
207 m_combo
->HidePopup();
213 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
215 m_combo
->HidePopup();
219 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
221 m_combo
->HidePopup();
225 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
227 m_combo
->HidePopup();
231 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
233 m_combo
->HidePopup();
237 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
239 m_combo
->HidePopup();
243 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
245 m_combo
->HidePopup();
249 #endif // INSTALL_TOPLEV_HANDLER
251 // ----------------------------------------------------------------------------
252 // wxComboPopupWindow is wxPopupWindow customized for
254 // ----------------------------------------------------------------------------
256 class wxComboPopupWindow
: public wxComboPopupWindowBase
260 wxComboPopupWindow( wxComboCtrlBase
*parent
, int style
= wxBORDER_NONE
);
262 #if USE_TRANSIENT_POPUP
263 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
266 void OnKeyEvent(wxKeyEvent
& event
);
268 void OnMouseEvent( wxMouseEvent
& event
);
270 void OnActivate( wxActivateEvent
& event
);
275 #if USE_TRANSIENT_POPUP
276 virtual void OnDismiss();
280 DECLARE_EVENT_TABLE()
284 BEGIN_EVENT_TABLE(wxComboPopupWindow
, wxComboPopupWindowBase
)
285 EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent
)
287 EVT_ACTIVATE(wxComboPopupWindow::OnActivate
)
289 EVT_KEY_DOWN(wxComboPopupWindow::OnKeyEvent
)
290 EVT_KEY_UP(wxComboPopupWindow::OnKeyEvent
)
294 wxComboPopupWindow::wxComboPopupWindow( wxComboCtrlBase
*parent
,
297 : wxComboPopupWindowBase(parent
,style
)
299 : wxComboPopupWindowBase(parent
,
309 void wxComboPopupWindow::OnKeyEvent( wxKeyEvent
& event
)
311 // Relay keyboard event to the main child controls
312 // (just skipping may just cause the popup to close)
313 wxWindowList children
= GetChildren();
314 wxWindowList::iterator node
= children
.begin();
315 wxWindow
* child
= (wxWindow
*)*node
;
316 child
->AddPendingEvent(event
);
319 void wxComboPopupWindow::OnMouseEvent( wxMouseEvent
& event
)
325 void wxComboPopupWindow::OnActivate( wxActivateEvent
& event
)
327 if ( !event
.GetActive() )
329 // Tell combo control that we are dismissed.
330 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
332 wxASSERT( combo
->IsKindOf(CLASSINFO(wxComboCtrl
)) );
341 #if USE_TRANSIENT_POPUP
342 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
344 return wxComboPopupWindowBase::ProcessLeftDown(event
);
348 #if USE_TRANSIENT_POPUP
349 // First thing that happens when a transient popup closes is that this method gets called.
350 void wxComboPopupWindow::OnDismiss()
352 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
353 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
354 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
356 combo
->OnPopupDismiss();
360 // ----------------------------------------------------------------------------
363 // ----------------------------------------------------------------------------
365 wxComboPopup::~wxComboPopup()
369 void wxComboPopup::OnPopup()
373 void wxComboPopup::OnDismiss()
377 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
379 int WXUNUSED(maxHeight
) )
381 return wxSize(minWidth
,prefHeight
);
384 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
385 wxDC
& dc
, const wxRect
& rect
)
387 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
389 combo
->PrepareBackground(dc
,rect
,0);
391 dc
.DrawText( combo
->GetValue(),
392 rect
.x
+ combo
->GetTextIndent(),
393 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
397 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
399 DefaultPaintComboControl(m_combo
,dc
,rect
);
402 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
407 void wxComboPopup::OnComboDoubleClick()
411 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
415 bool wxComboPopup::LazyCreate()
420 void wxComboPopup::Dismiss()
422 m_combo
->HidePopup();
425 // ----------------------------------------------------------------------------
427 // ----------------------------------------------------------------------------
430 // This is pushed to the event handler queue of the child textctrl.
432 class wxComboBoxExtraInputHandler
: public wxEvtHandler
436 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
441 virtual ~wxComboBoxExtraInputHandler() { }
442 void OnKey(wxKeyEvent
& event
);
443 void OnFocus(wxFocusEvent
& event
);
446 wxComboCtrlBase
* m_combo
;
449 DECLARE_EVENT_TABLE()
453 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
454 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
455 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
459 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
461 // Let the wxComboCtrl event handler have a go first.
462 wxComboCtrlBase
* combo
= m_combo
;
463 wxObject
* prevObj
= event
.GetEventObject();
465 event
.SetId(combo
->GetId());
466 event
.SetEventObject(combo
);
467 combo
->GetEventHandler()->ProcessEvent(event
);
469 event
.SetId(((wxWindow
*)prevObj
)->GetId());
470 event
.SetEventObject(prevObj
);
473 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
475 // FIXME: This code does run when control is clicked,
476 // yet on Windows it doesn't select all the text.
477 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
479 if ( m_combo
->GetTextCtrl() )
480 m_combo
->GetTextCtrl()->SelectAll();
482 m_combo
->SetSelection(-1,-1);
485 // Send focus indication to parent.
486 // NB: This is needed for cases where the textctrl gets focus
487 // instead of its parent. While this may trigger multiple
488 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
489 // from combo's focus event handler), they should be quite
491 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
492 evt2
.SetEventObject(m_combo
);
493 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
500 // This is pushed to the event handler queue of the control in popup.
503 class wxComboPopupExtraEventHandler
: public wxEvtHandler
507 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
511 m_beenInside
= false;
513 virtual ~wxComboPopupExtraEventHandler() { }
515 void OnMouseEvent( wxMouseEvent
& event
);
517 // Called from wxComboCtrlBase::OnPopupDismiss
518 void OnPopupDismiss()
520 m_beenInside
= false;
524 wxComboCtrlBase
* m_combo
;
529 DECLARE_EVENT_TABLE()
533 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
534 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
538 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
540 wxPoint pt
= event
.GetPosition();
541 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
542 int evtType
= event
.GetEventType();
543 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
545 if ( evtType
== wxEVT_MOTION
||
546 evtType
== wxEVT_LEFT_DOWN
||
547 evtType
== wxEVT_RIGHT_DOWN
)
549 // Block motion and click events outside the popup
556 else if ( evtType
== wxEVT_LEFT_UP
)
558 // Don't let left-down events in if outside
559 if ( evtType
== wxEVT_LEFT_DOWN
)
574 // Some mouse events to popup that happen outside it, before cursor
575 // has been inside the popu, need to be ignored by it but relayed to
578 wxWindow
* btn
= m_combo
->GetButton();
580 btn
->GetEventHandler()->AddPendingEvent(event
);
582 m_combo
->GetEventHandler()->AddPendingEvent(event
);
594 // ----------------------------------------------------------------------------
596 // ----------------------------------------------------------------------------
599 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
600 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
601 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
602 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
603 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
604 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
605 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
606 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
607 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
611 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
613 // Have global double buffer - should be enough for multiple combos
614 static wxBitmap
* gs_doubleBuffer
= (wxBitmap
*) NULL
;
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
) )
704 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
705 // not used by the wxPropertyGrid and therefore the tab is processed by
706 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
707 // navigation event is then sent to the wrong window.
708 style
|= wxTE_PROCESS_TAB
;
710 if ( HasFlag(wxTE_PROCESS_ENTER
) )
711 style
|= wxTE_PROCESS_ENTER
;
713 // Ignore EVT_TEXT generated by the constructor (but only
714 // if the event redirector already exists)
715 // NB: This must be " = 1" instead of "++";
716 if ( m_textEvtHandler
)
721 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
722 wxDefaultPosition
, wxDefaultSize
,
725 // This is required for some platforms (GTK+ atleast)
726 m_text
->SetSizeHints(2,4);
730 void wxComboCtrlBase::OnThemeChange()
732 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
735 wxComboCtrlBase::~wxComboCtrlBase()
740 delete gs_doubleBuffer
;
741 gs_doubleBuffer
= (wxBitmap
*) NULL
;
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 ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
892 int tcSizeY
= m_text
->GetBestSize().y
;
893 int diff
= sz
.y
- tcSizeY
;
894 int y
= textCtrlYAdjust
+ (diff
/2);
896 if ( y
< customBorder
)
899 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
901 m_tcArea
.width
- COMBO_MARGIN
-
902 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
905 // Make sure textctrl doesn't exceed the bottom custom border
906 wxSize tsz
= m_text
->GetSize();
907 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
910 tsz
.y
= tsz
.y
- diff
- 1;
911 m_text
->SetSize(tsz
);
916 m_text
->SetSize( m_tcArea
.x
,
918 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
923 wxSize
wxComboCtrlBase::DoGetBestSize() const
925 wxSize
sizeText(150,0);
928 sizeText
= m_text
->GetBestSize();
930 // TODO: Better method to calculate close-to-native control height.
934 fhei
= (m_font
.GetPointSize()*2) + 5;
935 else if ( wxNORMAL_FONT
->Ok() )
936 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
938 fhei
= sizeText
.y
+ 4;
940 // Need to force height to accomodate bitmap?
941 int btnSizeY
= m_btnSize
.y
;
942 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
945 // Control height doesn't depend on border
948 int border = m_windowStyle & wxBORDER_MASK;
949 if ( border == wxSIMPLE_BORDER )
951 else if ( border == wxNO_BORDER )
952 fhei += (m_widthCustomBorder*2);
963 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
970 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
975 // defined by actual wxComboCtrls
981 // ----------------------------------------------------------------------------
982 // standard operations
983 // ----------------------------------------------------------------------------
985 bool wxComboCtrlBase::Enable(bool enable
)
987 if ( !wxControl::Enable(enable
) )
991 m_btn
->Enable(enable
);
993 m_text
->Enable(enable
);
998 bool wxComboCtrlBase::Show(bool show
)
1000 if ( !wxControl::Show(show
) )
1012 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1014 if ( !wxControl::SetFont(font
) )
1018 m_text
->SetFont(font
);
1024 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1026 wxControl::DoSetToolTip(tooltip
);
1028 // Set tool tip for button and text box
1031 const wxString
&tip
= tooltip
->GetTip();
1032 if ( m_text
) m_text
->SetToolTip(tip
);
1033 if ( m_btn
) m_btn
->SetToolTip(tip
);
1037 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1038 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1041 #endif // wxUSE_TOOLTIPS
1043 // ----------------------------------------------------------------------------
1045 // ----------------------------------------------------------------------------
1047 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1048 // prepare combo box background on area in a way typical on platform
1049 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1051 wxSize sz
= GetClientSize();
1053 bool isFocused
; // also selected
1055 // For smaller size control (and for disabled background) use less spacing
1059 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1062 isEnabled
= IsEnabled();
1063 isFocused
= ShouldDrawFocus();
1065 // Windows-style: for smaller size control (and for disabled background) use less spacing
1066 focusSpacingX
= isEnabled
? 2 : 1;
1067 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1071 // Drawing a list item
1072 isEnabled
= true; // they are never disabled
1073 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1079 // Set the background sub-rectangle for selection, disabled etc
1080 wxRect
selRect(rect
);
1081 selRect
.y
+= focusSpacingY
;
1082 selRect
.height
-= (focusSpacingY
*2);
1086 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1087 wcp
+= m_widthCustomPaint
;
1089 selRect
.x
+= wcp
+ focusSpacingX
;
1090 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1096 // If popup is hidden and this control is focused,
1097 // then draw the focus-indicator (selbgcolor background etc.).
1100 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1101 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1105 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1106 bgCol
= GetBackgroundColour();
1111 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1112 bgCol
= GetBackgroundColour();
1115 dc
.SetBrush( bgCol
);
1117 dc
.DrawRectangle( selRect
);
1119 // Don't clip exactly to the selection rectangle so we can draw
1120 // to the non-selected area in front of it.
1121 wxRect
clipRect(rect
.x
,rect
.y
,
1122 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1123 dc
.SetClippingRegion(clipRect
);
1126 // Save the library size a bit for platforms that re-implement this.
1127 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1132 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1134 int drawState
= m_btnState
;
1137 if ( m_isPopupShown
)
1138 drawState
|= wxCONTROL_PRESSED
;
1141 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1142 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1146 // Make sure area is not larger than the control
1147 if ( drawRect
.y
< rect
.y
)
1148 drawRect
.y
= rect
.y
;
1149 if ( drawRect
.height
> rect
.height
)
1150 drawRect
.height
= rect
.height
;
1152 bool enabled
= IsEnabled();
1155 drawState
|= wxCONTROL_DISABLED
;
1157 if ( !m_bmpNormal
.Ok() )
1159 // Need to clear button background even if m_btn is present
1164 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1165 bgCol
= GetParent()->GetBackgroundColour();
1167 bgCol
= GetBackgroundColour();
1171 dc
.DrawRectangle(rect
);
1174 // Draw standard button
1175 wxRendererNative::Get().DrawComboBoxDropButton(this,
1187 pBmp
= &m_bmpDisabled
;
1188 else if ( m_btnState
& wxCONTROL_PRESSED
)
1189 pBmp
= &m_bmpPressed
;
1190 else if ( m_btnState
& wxCONTROL_CURRENT
)
1193 pBmp
= &m_bmpNormal
;
1195 if ( m_blankButtonBg
)
1197 // If using blank button background, we need to clear its background
1198 // with button face colour instead of colour for rest of the control.
1201 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1202 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1205 dc
.DrawRectangle(rect
);
1208 wxRendererNative::Get().DrawPushButton(this,
1217 // Need to clear button background even if m_btn is present
1218 // (assume non-button background was cleared just before this call so brushes are good)
1220 dc
.DrawRectangle(rect
);
1223 // Draw bitmap centered in drawRect
1224 dc
.DrawBitmap(*pBmp
,
1225 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1226 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1231 void wxComboCtrlBase::RecalcAndRefresh()
1235 wxSizeEvent
evt(GetSize(),GetId());
1236 GetEventHandler()->ProcessEvent(evt
);
1241 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1243 // If size is larger, recalculate double buffer bitmap
1244 if ( !gs_doubleBuffer
||
1245 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1246 sz
.y
> gs_doubleBuffer
->GetHeight() )
1248 delete gs_doubleBuffer
;
1249 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1251 return *gs_doubleBuffer
;
1254 // ----------------------------------------------------------------------------
1255 // miscellaneous event handlers
1256 // ----------------------------------------------------------------------------
1258 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1260 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1262 if ( m_ignoreEvtText
> 0 )
1269 // Change event id, object and string before relaying it forward
1270 event
.SetId(GetId());
1271 wxString s
= event
.GetString();
1272 event
.SetEventObject(this);
1277 // call if cursor is on button area or mouse is captured for the button
1278 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1281 int type
= event
.GetEventType();
1283 if ( type
== wxEVT_MOTION
)
1285 if ( flags
& wxCC_MF_ON_BUTTON
)
1287 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1289 // Mouse hover begins
1290 m_btnState
|= wxCONTROL_CURRENT
;
1291 if ( HasCapture() ) // Retain pressed state.
1292 m_btnState
|= wxCONTROL_PRESSED
;
1296 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1299 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1303 else if ( type
== wxEVT_LEFT_DOWN
)
1305 // Only accept event if it wasn't right after popup dismiss
1306 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1308 // Need to test this, because it might be outside.
1309 if ( flags
& wxCC_MF_ON_BUTTON
)
1311 m_btnState
|= wxCONTROL_PRESSED
;
1314 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1317 // If showing popup now, do not capture mouse or there will be interference
1326 else if ( type
== wxEVT_LEFT_UP
)
1329 // Only accept event if mouse was left-press was previously accepted
1333 if ( m_btnState
& wxCONTROL_PRESSED
)
1335 // If mouse was inside, fire the click event.
1336 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1338 if ( flags
& wxCC_MF_ON_BUTTON
)
1342 m_btnState
&= ~(wxCONTROL_PRESSED
);
1346 else if ( type
== wxEVT_LEAVE_WINDOW
)
1348 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1350 m_btnState
&= ~(wxCONTROL_CURRENT
);
1353 if ( !m_isPopupShown
)
1355 m_btnState
&= ~(wxCONTROL_PRESSED
);
1366 // returns true if event was consumed or filtered
1367 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1368 int WXUNUSED(flags
) )
1370 wxLongLong t
= ::wxGetLocalTimeMillis();
1371 int evtType
= event
.GetEventType();
1373 #if !USE_TRANSIENT_POPUP
1374 if ( m_isPopupShown
&&
1375 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1382 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1383 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1385 event
.SetEventType(0);
1392 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1394 int evtType
= event
.GetEventType();
1396 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1397 (m_windowStyle
& wxCB_READONLY
) )
1399 if ( m_isPopupShown
)
1402 // Normally do nothing - evt handler should close it for us
1403 #elif !USE_TRANSIENT_POPUP
1404 // Click here always hides the popup.
1410 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1412 // In read-only mode, clicking the text is the
1413 // same as clicking the button.
1416 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1418 //if ( m_popupInterface->CycleValue() )
1420 if ( m_popupInterface
)
1421 m_popupInterface
->OnComboDoubleClick();
1426 if ( m_isPopupShown
)
1428 // relay (some) mouse events to the popup
1429 if ( evtType
== wxEVT_MOUSEWHEEL
)
1430 m_popup
->AddPendingEvent(event
);
1436 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1438 if ( IsPopupShown() )
1440 // pass it to the popped up control
1441 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1445 int keycode
= event
.GetKeyCode();
1447 if ( keycode
== WXK_TAB
)
1449 wxNavigationKeyEvent evt
;
1450 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1451 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1452 : wxNavigationKeyEvent::IsBackward
));
1453 evt
.SetEventObject(this);
1454 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1458 if ( IsKeyPopupToggle(event
) )
1464 int comboStyle
= GetWindowStyle();
1465 wxComboPopup
* popupInterface
= GetPopupControl();
1467 if ( !popupInterface
)
1473 if ( (comboStyle
& wxCB_READONLY
) ||
1474 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1476 popupInterface
->OnComboKeyEvent(event
);
1483 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1485 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1487 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1494 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1497 // indentation may also have changed
1498 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1499 m_absIndent
= GetNativeTextIndent();
1503 // ----------------------------------------------------------------------------
1505 // ----------------------------------------------------------------------------
1507 // Create popup window and the child control
1508 void wxComboCtrlBase::CreatePopup()
1510 wxComboPopup
* popupInterface
= m_popupInterface
;
1514 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1516 popupInterface
->Create(m_winPopup
);
1517 m_popup
= popup
= popupInterface
->GetControl();
1519 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1520 popup
->PushEventHandler( m_popupExtraHandler
);
1522 // This may be helpful on some platforms
1523 // (eg. it bypasses a wxGTK popupwindow bug where
1524 // window is not initially hidden when it should be)
1527 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1530 // Destroy popup window and the child control
1531 void wxComboCtrlBase::DestroyPopup()
1536 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1538 delete m_popupExtraHandler
;
1540 delete m_popupInterface
;
1543 m_winPopup
->Destroy();
1545 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1546 m_popupInterface
= (wxComboPopup
*) NULL
;
1547 m_winPopup
= (wxWindow
*) NULL
;
1548 m_popup
= (wxWindow
*) NULL
;
1551 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1553 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1557 iface
->InitBase(this);
1560 m_popupInterface
= iface
;
1562 if ( !iface
->LazyCreate() )
1568 m_popup
= (wxWindow
*) NULL
;
1571 // This must be done after creation
1572 if ( m_valueString
.length() )
1574 iface
->SetStringValue(m_valueString
);
1579 // Ensures there is atleast the default popup
1580 void wxComboCtrlBase::EnsurePopupControl()
1582 if ( !m_popupInterface
)
1583 SetPopupControl(NULL
);
1586 void wxComboCtrlBase::OnButtonClick()
1588 // Derived classes can override this method for totally custom
1593 void wxComboCtrlBase::ShowPopup()
1595 EnsurePopupControl();
1596 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1600 // Space above and below
1606 wxSize ctrlSz
= GetSize();
1608 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1609 scrPos
= GetParent()->ClientToScreen(GetPosition());
1611 spaceAbove
= scrPos
.y
;
1612 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1614 maxHeightPopup
= spaceBelow
;
1615 if ( spaceAbove
> spaceBelow
)
1616 maxHeightPopup
= spaceAbove
;
1619 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1621 if ( widthPopup
< m_widthMinPopup
)
1622 widthPopup
= m_widthMinPopup
;
1624 wxWindow
* winPopup
= m_winPopup
;
1627 // Need to disable tab traversal of parent
1629 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1630 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1631 // that if transient popup is open, then tab traversal is to be ignored.
1632 // However, I think this code would still be needed for cases where
1633 // transient popup doesn't work yet (wxWinCE?).
1634 wxWindow
* parent
= GetParent();
1635 int parentFlags
= parent
->GetWindowStyle();
1636 if ( parentFlags
& wxTAB_TRAVERSAL
)
1638 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1639 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1645 winPopup
= m_winPopup
;
1653 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1655 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1656 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1659 popup
->SetSize(adjustedSize
);
1661 m_popupInterface
->OnPopup();
1664 // Reposition and resize popup window
1667 wxSize szp
= popup
->GetSize();
1670 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1672 // Default anchor is wxLEFT
1673 int anchorSide
= m_anchorSide
;
1675 anchorSide
= wxLEFT
;
1677 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1678 int leftX
= scrPos
.x
- m_extLeft
;
1679 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1681 // If there is not enough horizontal space, anchor on the other side.
1682 // If there is no space even then, place the popup at x 0.
1683 if ( anchorSide
== wxRIGHT
)
1687 if ( (leftX
+szp
.x
) < screenWidth
)
1688 anchorSide
= wxLEFT
;
1695 if ( (leftX
+szp
.x
) >= screenWidth
)
1698 anchorSide
= wxRIGHT
;
1704 // Select x coordinate according to the anchor side
1705 if ( anchorSide
== wxRIGHT
)
1707 else if ( anchorSide
== wxLEFT
)
1712 if ( spaceBelow
< szp
.y
)
1714 popupY
= scrPos
.y
- szp
.y
;
1718 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1719 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1721 // Some platforms (GTK) may need these two to be separate
1722 winPopup
->SetSize( szp
.x
, szp
.y
);
1723 winPopup
->Move( popupX
, popupY
);
1725 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1729 // Set string selection (must be this way instead of SetStringSelection)
1732 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1733 m_text
->SelectAll();
1735 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1739 // This is neede since focus/selection indication may change when popup is shown
1743 // This must be after SetStringValue
1744 m_isPopupShown
= true;
1747 #if USE_TRANSIENT_POPUP
1748 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1753 #if INSTALL_TOPLEV_HANDLER
1754 // Put top level window event handler into place
1755 if ( !m_toplevEvtHandler
)
1756 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1758 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1760 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1761 toplev
->PushEventHandler( m_toplevEvtHandler
);
1766 void wxComboCtrlBase::OnPopupDismiss()
1768 // Just in case, avoid double dismiss
1769 if ( !m_isPopupShown
)
1772 // *Must* set this before focus etc.
1773 m_isPopupShown
= false;
1775 // Inform popup control itself
1776 m_popupInterface
->OnDismiss();
1778 if ( m_popupExtraHandler
)
1779 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1781 #if INSTALL_TOPLEV_HANDLER
1782 // Remove top level window event handler
1783 if ( m_toplevEvtHandler
)
1785 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1787 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1791 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1793 // If cursor not on dropdown button, then clear its state
1794 // (technically not required by all ports, but do it for all just in case)
1795 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1798 // Return parent's tab traversal flag.
1799 // See ShowPopup for notes.
1800 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1802 wxWindow
* parent
= GetParent();
1803 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1804 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1807 // refresh control (necessary even if m_text)
1816 void wxComboCtrlBase::HidePopup()
1818 // Should be able to call this without popup interface
1819 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1820 if ( !m_isPopupShown
)
1823 // transfer value and show it in textctrl, if any
1824 SetValue( m_popupInterface
->GetStringValue() );
1826 #if USE_TRANSIENT_POPUP
1827 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1835 // ----------------------------------------------------------------------------
1836 // customization methods
1837 // ----------------------------------------------------------------------------
1839 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1840 int side
, int spacingX
)
1845 m_btnSpacingX
= spacingX
;
1850 wxSize
wxComboCtrlBase::GetButtonSize()
1852 if ( m_btnSize
.x
> 0 )
1855 wxSize
retSize(m_btnWid
,m_btnHei
);
1857 // Need to call CalculateAreas now if button size is
1858 // is not explicitly specified.
1859 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1863 retSize
= m_btnSize
;
1869 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1871 const wxBitmap
& bmpPressed
,
1872 const wxBitmap
& bmpHover
,
1873 const wxBitmap
& bmpDisabled
)
1875 m_bmpNormal
= bmpNormal
;
1876 m_blankButtonBg
= blankButtonBg
;
1878 if ( bmpPressed
.Ok() )
1879 m_bmpPressed
= bmpPressed
;
1881 m_bmpPressed
= bmpNormal
;
1883 if ( bmpHover
.Ok() )
1884 m_bmpHover
= bmpHover
;
1886 m_bmpHover
= bmpNormal
;
1888 if ( bmpDisabled
.Ok() )
1889 m_bmpDisabled
= bmpDisabled
;
1891 m_bmpDisabled
= bmpNormal
;
1896 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1900 // move textctrl accordingly
1901 wxRect r
= m_text
->GetRect();
1902 int inc
= width
- m_widthCustomPaint
;
1905 m_text
->SetSize( r
);
1908 m_widthCustomPaint
= width
;
1913 void wxComboCtrlBase::SetTextIndent( int indent
)
1917 m_absIndent
= GetNativeTextIndent();
1918 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1922 m_absIndent
= indent
;
1923 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1929 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1931 return DEFAULT_TEXT_INDENT
;
1934 // ----------------------------------------------------------------------------
1935 // methods forwarded to wxTextCtrl
1936 // ----------------------------------------------------------------------------
1938 wxString
wxComboCtrlBase::GetValue() const
1941 return m_text
->GetValue();
1942 return m_valueString
;
1945 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
1952 m_text
->SetValue(value
);
1953 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1954 m_text
->SelectAll();
1957 m_valueString
= value
;
1961 // Since wxComboPopup may want to paint the combo as well, we need
1962 // to set the string value here (as well as sometimes in ShowPopup).
1963 if ( m_valueString
!= value
&& m_popupInterface
)
1965 m_popupInterface
->SetStringValue(value
);
1969 void wxComboCtrlBase::SetValue(const wxString
& value
)
1971 SetValueWithEvent(value
, false);
1974 // In this SetValue variant wxComboPopup::SetStringValue is not called
1975 void wxComboCtrlBase::SetText(const wxString
& value
)
1977 // Unlike in SetValue(), this must be called here or
1978 // the behaviour will no be consistent in readonlys.
1979 EnsurePopupControl();
1981 m_valueString
= value
;
1986 m_text
->SetValue( value
);
1992 void wxComboCtrlBase::Copy()
1998 void wxComboCtrlBase::Cut()
2004 void wxComboCtrlBase::Paste()
2010 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2013 m_text
->SetInsertionPoint(pos
);
2016 void wxComboCtrlBase::SetInsertionPointEnd()
2019 m_text
->SetInsertionPointEnd();
2022 long wxComboCtrlBase::GetInsertionPoint() const
2025 return m_text
->GetInsertionPoint();
2030 long wxComboCtrlBase::GetLastPosition() const
2033 return m_text
->GetLastPosition();
2038 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2041 m_text
->Replace(from
, to
, value
);
2044 void wxComboCtrlBase::Remove(long from
, long to
)
2047 m_text
->Remove(from
, to
);
2050 void wxComboCtrlBase::SetSelection(long from
, long to
)
2053 m_text
->SetSelection(from
, to
);
2056 void wxComboCtrlBase::Undo()
2062 #endif // wxUSE_COMBOCTRL