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"
30 #include "wx/combobox.h"
31 #include "wx/dcclient.h"
32 #include "wx/settings.h"
33 #include "wx/dialog.h"
37 #include "wx/dcbuffer.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 200
57 #define DEFAULT_TEXT_INDENT 3
59 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
62 #if defined(__WXMSW__)
64 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
66 //#undef wxUSE_POPUPWIN
67 //#define wxUSE_POPUPWIN 0
69 #elif defined(__WXGTK__)
71 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
73 #elif defined(__WXMAC__)
75 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
79 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
84 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
85 // what the wxUSE_POPUPWIN says.
86 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
87 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
89 #define wxUSE_POPUPWIN 0
94 #include "wx/popupwin.h"
96 #undef USE_TRANSIENT_POPUP
97 #define USE_TRANSIENT_POPUP 0
101 #if USE_TRANSIENT_POPUP
103 #define wxComboPopupWindowBase wxPopupTransientWindow
104 #define INSTALL_TOPLEV_HANDLER 0
108 #define wxComboPopupWindowBase wxPopupWindow
109 #define INSTALL_TOPLEV_HANDLER 1
113 #define wxComboPopupWindowBase wxDialog
114 #define INSTALL_TOPLEV_HANDLER 0 // Doesn't need since can monitor active event
122 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
126 // ----------------------------------------------------------------------------
127 // wxComboFrameEventHandler takes care of hiding the popup when events happen
128 // in its top level parent.
129 // ----------------------------------------------------------------------------
131 #if INSTALL_TOPLEV_HANDLER
134 // This will no longer be necessary after wxTransientPopupWindow
135 // works well on all platforms.
138 class wxComboFrameEventHandler
: public wxEvtHandler
141 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
142 ~wxComboFrameEventHandler();
146 void OnIdle( wxIdleEvent
& event
);
147 void OnMouseEvent( wxMouseEvent
& event
);
148 void OnActivate( wxActivateEvent
& event
);
149 void OnResize( wxSizeEvent
& event
);
150 void OnMove( wxMoveEvent
& event
);
151 void OnMenuEvent( wxMenuEvent
& event
);
152 void OnClose( wxCloseEvent
& event
);
155 wxWindow
* m_focusStart
;
156 wxComboCtrlBase
* m_combo
;
159 DECLARE_EVENT_TABLE()
162 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
163 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
164 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
165 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
166 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
167 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
168 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
169 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
170 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
171 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
174 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
180 wxComboFrameEventHandler::~wxComboFrameEventHandler()
184 void wxComboFrameEventHandler::OnPopup()
186 m_focusStart
= ::wxWindow::FindFocus();
189 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
191 wxWindow
* winFocused
= ::wxWindow::FindFocus();
193 wxWindow
* popup
= m_combo
->GetPopupControl();
194 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
197 winFocused
!= m_focusStart
&&
198 winFocused
!= popup
&&
199 winFocused
->GetParent() != popup
&&
200 winFocused
!= winpopup
&&
201 winFocused
->GetParent() != winpopup
&&
202 winFocused
!= m_combo
&&
203 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
206 m_combo
->HidePopup();
212 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
214 m_combo
->HidePopup();
218 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
220 m_combo
->HidePopup();
224 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
226 m_combo
->HidePopup();
230 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
232 m_combo
->HidePopup();
236 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
238 m_combo
->HidePopup();
242 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
244 m_combo
->HidePopup();
248 #endif // INSTALL_TOPLEV_HANDLER
250 // ----------------------------------------------------------------------------
251 // wxComboPopupWindow is wxPopupWindow customized for
253 // ----------------------------------------------------------------------------
255 class wxComboPopupWindow
: public wxComboPopupWindowBase
259 wxComboPopupWindow( wxComboCtrlBase
*parent
, int style
= wxBORDER_NONE
);
261 #if USE_TRANSIENT_POPUP
262 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
265 void OnKeyEvent(wxKeyEvent
& event
);
267 void OnMouseEvent( wxMouseEvent
& event
);
269 void OnActivate( wxActivateEvent
& event
);
274 #if USE_TRANSIENT_POPUP
275 virtual void OnDismiss();
279 DECLARE_EVENT_TABLE()
283 BEGIN_EVENT_TABLE(wxComboPopupWindow
, wxComboPopupWindowBase
)
284 EVT_MOUSE_EVENTS(wxComboPopupWindow::OnMouseEvent
)
286 EVT_ACTIVATE(wxComboPopupWindow::OnActivate
)
288 EVT_KEY_DOWN(wxComboPopupWindow::OnKeyEvent
)
289 EVT_KEY_UP(wxComboPopupWindow::OnKeyEvent
)
293 wxComboPopupWindow::wxComboPopupWindow( wxComboCtrlBase
*parent
,
296 : wxComboPopupWindowBase(parent
,style
)
298 : wxComboPopupWindowBase(parent
,
308 void wxComboPopupWindow::OnKeyEvent( wxKeyEvent
& event
)
310 // Relay keyboard event to the main child controls
311 // (just skipping may just cause the popup to close)
312 wxWindowList children
= GetChildren();
313 wxWindowList::iterator node
= children
.begin();
314 wxWindow
* child
= (wxWindow
*)*node
;
315 child
->AddPendingEvent(event
);
318 void wxComboPopupWindow::OnMouseEvent( wxMouseEvent
& event
)
324 void wxComboPopupWindow::OnActivate( wxActivateEvent
& event
)
326 if ( !event
.GetActive() )
328 // Tell combo control that we are dismissed.
329 wxComboCtrl
* combo
= (wxComboCtrl
*) GetParent();
331 wxASSERT( combo
->IsKindOf(CLASSINFO(wxComboCtrl
)) );
340 #if USE_TRANSIENT_POPUP
341 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
343 return wxComboPopupWindowBase::ProcessLeftDown(event
);
347 #if USE_TRANSIENT_POPUP
348 // First thing that happens when a transient popup closes is that this method gets called.
349 void wxComboPopupWindow::OnDismiss()
351 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
352 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
353 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
355 combo
->OnPopupDismiss();
359 // ----------------------------------------------------------------------------
362 // ----------------------------------------------------------------------------
364 wxComboPopup::~wxComboPopup()
368 void wxComboPopup::OnPopup()
372 void wxComboPopup::OnDismiss()
376 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
378 int WXUNUSED(maxHeight
) )
380 return wxSize(minWidth
,prefHeight
);
383 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
384 wxDC
& dc
, const wxRect
& rect
)
386 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
388 combo
->DrawFocusBackground(dc
,rect
,0);
390 dc
.DrawText( combo
->GetValue(),
391 rect
.x
+ combo
->GetTextIndent(),
392 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
396 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
398 DefaultPaintComboControl(m_combo
,dc
,rect
);
401 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
406 void wxComboPopup::OnComboDoubleClick()
410 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
414 bool wxComboPopup::LazyCreate()
419 void wxComboPopup::Dismiss()
421 m_combo
->HidePopup();
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
429 // This is pushed to the event handler queue of either combo box
430 // or its textctrl (latter if not readonly combo).
432 class wxComboBoxExtraInputHandler
: public wxEvtHandler
436 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
441 ~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 int keycode
= event
.GetKeyCode();
463 if ( keycode
== WXK_TAB
)
465 wxNavigationKeyEvent evt
;
466 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
467 (!event
.ShiftDown()?wxNavigationKeyEvent::IsForward
:
468 wxNavigationKeyEvent::IsBackward
));
469 evt
.SetEventObject(m_combo
);
470 m_combo
->GetParent()->GetEventHandler()->AddPendingEvent(evt
);
474 if ( m_combo
->IsPopupShown() )
476 // pass it to the popped up control
477 m_combo
->GetPopupControl()->GetControl()->AddPendingEvent(event
);
481 int comboStyle
= m_combo
->GetWindowStyle();
482 wxComboPopup
* popupInterface
= m_combo
->GetPopupControl();
484 if ( !popupInterface
)
490 if ( (comboStyle
& wxCB_READONLY
) ||
491 ( keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
)
494 // Alternate keys: UP and DOWN show the popup instead of cycling
495 if ( (comboStyle
& wxCC_ALT_KEYS
) )
497 if ( keycode
== WXK_UP
|| keycode
== WXK_DOWN
)
499 m_combo
->OnButtonClick();
506 popupInterface
->OnComboKeyEvent(event
);
513 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
515 // FIXME: This code does run when control is clicked,
516 // yet on Windows it doesn't select all the text.
517 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
519 if ( m_combo
->GetTextCtrl() )
520 m_combo
->GetTextCtrl()->SelectAll();
522 m_combo
->SetSelection(-1,-1);
525 if ( event
.GetId() != m_combo
->GetId() )
527 // Add textctrl set focus events as combo set focus events
528 // NOTE: Simply changing the event and skipping didn't seem
530 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
531 evt2
.SetEventObject(m_combo
);
532 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
542 // This is pushed to the event handler queue of the control in popup.
545 class wxComboPopupExtraEventHandler
: public wxEvtHandler
549 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
553 m_beenInside
= false;
555 ~wxComboPopupExtraEventHandler() { }
557 void OnMouseEvent( wxMouseEvent
& event
);
559 // Called from wxComboCtrlBase::OnPopupDismiss
560 void OnPopupDismiss()
562 m_beenInside
= false;
566 wxComboCtrlBase
* m_combo
;
571 DECLARE_EVENT_TABLE()
575 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
576 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
580 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
582 wxPoint pt
= event
.GetPosition();
583 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
584 int evtType
= event
.GetEventType();
585 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
587 if ( evtType
== wxEVT_MOTION
||
588 evtType
== wxEVT_LEFT_DOWN
||
589 evtType
== wxEVT_RIGHT_DOWN
)
591 // Block motion and click events outside the popup
598 else if ( evtType
== wxEVT_LEFT_UP
)
600 // Don't let left-down events in if outside
601 if ( evtType
== wxEVT_LEFT_DOWN
)
616 // Some mouse events to popup that happen outside it, before cursor
617 // has been inside the popu, need to be ignored by it but relayed to
620 wxWindow
* btn
= m_combo
->GetButton();
622 btn
->GetEventHandler()->AddPendingEvent(event
);
624 m_combo
->GetEventHandler()->AddPendingEvent(event
);
636 // ----------------------------------------------------------------------------
638 // ----------------------------------------------------------------------------
641 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
642 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
643 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
644 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
645 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
646 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
647 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
648 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
652 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
654 // Have global double buffer - should be enough for multiple combos
655 static wxBitmap
* gs_doubleBuffer
= (wxBitmap
*) NULL
;
657 void wxComboCtrlBase::Init()
659 m_winPopup
= (wxWindow
*)NULL
;
660 m_popup
= (wxWindow
*)NULL
;
661 m_isPopupShown
= false;
662 m_btn
= (wxWindow
*) NULL
;
663 m_text
= (wxTextCtrl
*) NULL
;
664 m_popupInterface
= (wxComboPopup
*) NULL
;
666 m_extraEvtHandler
= (wxEvtHandler
*) NULL
;
667 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
668 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
670 #if INSTALL_TOPLEV_HANDLER
671 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
675 m_widthMinPopup
= -1;
677 m_widthCustomPaint
= 0;
678 m_widthCustomBorder
= 0;
682 m_blankButtonBg
= false;
683 m_btnWid
= m_btnHei
= 0;
691 m_downReceived
= false;
692 m_timeCanAcceptClick
= 0;
695 bool wxComboCtrlBase::Create(wxWindow
*parent
,
697 const wxString
& value
,
701 const wxValidator
& validator
,
702 const wxString
& name
)
704 if ( !wxControl::Create(parent
,
708 style
| wxWANTS_CHARS
,
713 m_valueString
= value
;
717 m_absIndent
= GetNativeTextIndent();
719 m_iFlags
|= wxCC_IFLAG_CREATED
;
721 // If x and y indicate valid size, wxSizeEvent won't be
722 // emitted automatically, so we need to add artifical one.
723 if ( size
.x
> 0 && size
.y
> 0 )
725 wxSizeEvent
evt(size
,GetId());
726 GetEventHandler()->AddPendingEvent(evt
);
732 void wxComboCtrlBase::InstallInputHandlers( bool alsoTextCtrl
)
734 if ( m_text
&& alsoTextCtrl
)
736 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
737 m_text
->PushEventHandler(m_textEvtHandler
);
740 wxComboBoxExtraInputHandler
* inputHandler
= new wxComboBoxExtraInputHandler(this);
741 PushEventHandler(inputHandler
);
742 m_extraEvtHandler
= inputHandler
;
745 void wxComboCtrlBase::CreateTextCtrl( int extraStyle
, const wxValidator
& validator
)
747 if ( !(m_windowStyle
& wxCB_READONLY
) )
749 m_text
= new wxTextCtrl(this,
754 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
755 // not used by the wxPropertyGrid and therefore the tab is
756 // processed by looking at ancestors to see if they have
757 // wxTAB_TRAVERSAL. The navigation event is then sent to
764 // This is required for some platforms (GTK+ atleast)
765 m_text
->SetSizeHints(2,4);
769 void wxComboCtrlBase::OnThemeChange()
771 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
774 wxComboCtrlBase::~wxComboCtrlBase()
779 delete gs_doubleBuffer
;
780 gs_doubleBuffer
= (wxBitmap
*) NULL
;
782 #if INSTALL_TOPLEV_HANDLER
783 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
784 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
789 RemoveEventHandler(m_extraEvtHandler
);
792 m_text
->RemoveEventHandler(m_textEvtHandler
);
794 delete m_textEvtHandler
;
795 delete m_extraEvtHandler
;
799 // ----------------------------------------------------------------------------
801 // ----------------------------------------------------------------------------
803 // Recalculates button and textctrl areas
804 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
806 wxSize sz
= GetClientSize();
807 int customBorder
= m_widthCustomBorder
;
808 int btnBorder
; // border for button only
810 // check if button should really be outside the border: we'll do it it if
811 // its platform default or bitmap+pushbutton background is used, but not if
812 // there is vertical size adjustment or horizontal spacing.
813 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
814 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
815 m_btnSpacingX
== 0 &&
818 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
823 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
824 btnBorder
= customBorder
;
827 // Defaul indentation
828 if ( m_absIndent
< 0 )
829 m_absIndent
= GetNativeTextIndent();
831 int butWidth
= btnWidth
;
834 butWidth
= m_btnWidDefault
;
836 m_btnWidDefault
= butWidth
;
841 int butHeight
= sz
.y
- btnBorder
*2;
843 // Adjust button width
845 butWidth
+= m_btnWid
;
846 else if ( m_btnWid
> 0 )
850 // Adjust button width to match aspect ratio
851 // (but only if control is smaller than best size).
852 int bestHeight
= GetBestSize().y
;
853 int height
= GetSize().y
;
855 if ( height
< bestHeight
)
857 // Make very small buttons square, as it makes
858 // them accommodate arrow image better and still
861 butWidth
= (height
*butWidth
)/bestHeight
;
863 butWidth
= butHeight
;
867 // Adjust button height
869 butHeight
+= m_btnHei
;
870 else if ( m_btnHei
> 0 )
871 butHeight
= m_btnHei
;
873 // Use size of normal bitmap if...
876 // button width is set to default and blank button bg is not drawn
877 if ( m_bmpNormal
.Ok() )
879 int bmpReqWidth
= m_bmpNormal
.GetWidth();
880 int bmpReqHeight
= m_bmpNormal
.GetHeight();
882 // If drawing blank button background, we need to add some margin.
883 if ( m_blankButtonBg
)
885 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
886 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
889 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
890 butWidth
= bmpReqWidth
;
891 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
892 butHeight
= bmpReqHeight
;
894 // Need to fix height?
895 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
897 int newY
= butHeight
+(customBorder
*2);
898 SetClientSize(-1,newY
);
903 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
905 m_btnSize
.x
= butWidth
;
906 m_btnSize
.y
= butHeight
;
908 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
909 m_btnArea
.y
= btnBorder
;
910 m_btnArea
.width
= butAreaWid
;
911 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
913 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
914 m_tcArea
.y
= customBorder
;
915 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
916 m_tcArea
.height
= sz
.y
- (customBorder
*2);
921 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
922 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
927 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
932 wxSize sz
= GetClientSize();
933 int customBorder
= m_widthCustomBorder
;
935 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
938 int tcSizeY
= m_text
->GetBestSize().y
;
939 int diff
= sz
.y
- tcSizeY
;
940 int y
= textCtrlYAdjust
+ (diff
/2);
942 if ( y
< customBorder
)
945 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
947 m_tcArea
.width
- COMBO_MARGIN
-
948 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
951 // Make sure textctrl doesn't exceed the bottom custom border
952 wxSize tsz
= m_text
->GetSize();
953 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
956 tsz
.y
= tsz
.y
- diff
- 1;
957 m_text
->SetSize(tsz
);
962 m_text
->SetSize( m_tcArea
.x
,
964 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
969 wxSize
wxComboCtrlBase::DoGetBestSize() const
971 wxSize
sizeText(150,0);
974 sizeText
= m_text
->GetBestSize();
976 // TODO: Better method to calculate close-to-native control height.
980 fhei
= (m_font
.GetPointSize()*2) + 5;
981 else if ( wxNORMAL_FONT
->Ok() )
982 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
984 fhei
= sizeText
.y
+ 4;
986 // Need to force height to accomodate bitmap?
987 int btnSizeY
= m_btnSize
.y
;
988 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
991 // Control height doesn't depend on border
994 int border = m_windowStyle & wxBORDER_MASK;
995 if ( border == wxSIMPLE_BORDER )
997 else if ( border == wxNO_BORDER )
998 fhei += (m_widthCustomBorder*2);
1004 // Final adjustments
1009 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
1016 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1021 // defined by actual wxComboCtrls
1027 // ----------------------------------------------------------------------------
1028 // standard operations
1029 // ----------------------------------------------------------------------------
1031 bool wxComboCtrlBase::Enable(bool enable
)
1033 if ( !wxControl::Enable(enable
) )
1037 m_btn
->Enable(enable
);
1039 m_text
->Enable(enable
);
1044 bool wxComboCtrlBase::Show(bool show
)
1046 if ( !wxControl::Show(show
) )
1058 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1060 if ( !wxControl::SetFont(font
) )
1064 m_text
->SetFont(font
);
1070 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1072 wxControl::DoSetToolTip(tooltip
);
1074 // Set tool tip for button and text box
1077 const wxString
&tip
= tooltip
->GetTip();
1078 if ( m_text
) m_text
->SetToolTip(tip
);
1079 if ( m_btn
) m_btn
->SetToolTip(tip
);
1083 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1084 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1087 #endif // wxUSE_TOOLTIPS
1089 // ----------------------------------------------------------------------------
1091 // ----------------------------------------------------------------------------
1093 // draw focus background on area in a way typical on platform
1094 void wxComboCtrlBase::DrawFocusBackground( wxDC
& dc
, const wxRect
& rect
, int flags
)
1096 wxSize sz
= GetClientSize();
1098 bool isFocused
; // also selected
1100 // For smaller size control (and for disabled background) use less spacing
1104 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1107 isEnabled
= IsEnabled();
1108 isFocused
= ShouldDrawFocus();
1110 // Windows-style: for smaller size control (and for disabled background) use less spacing
1111 focusSpacingX
= isEnabled
? 2 : 1;
1112 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1116 // Drawing a list item
1117 isEnabled
= true; // they are never disabled
1118 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1124 // Set the background sub-rectangle for selection, disabled etc
1125 wxRect
selRect(rect
);
1126 selRect
.y
+= focusSpacingY
;
1127 selRect
.height
-= (focusSpacingY
*2);
1128 selRect
.x
+= m_widthCustomPaint
+ focusSpacingX
;
1129 selRect
.width
-= m_widthCustomPaint
+ (focusSpacingX
*2);
1135 // If popup is hidden and this control is focused,
1136 // then draw the focus-indicator (selbgcolor background etc.).
1139 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1140 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1144 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1145 bgCol
= GetBackgroundColour();
1150 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1151 bgCol
= GetBackgroundColour();
1154 dc
.SetBrush( bgCol
);
1156 dc
.DrawRectangle( selRect
);
1159 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1161 int drawState
= m_btnState
;
1164 if ( m_isPopupShown
)
1165 drawState
|= wxCONTROL_PRESSED
;
1168 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1169 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1173 // Make sure area is not larger than the control
1174 if ( drawRect
.y
< rect
.y
)
1175 drawRect
.y
= rect
.y
;
1176 if ( drawRect
.height
> rect
.height
)
1177 drawRect
.height
= rect
.height
;
1179 bool enabled
= IsEnabled();
1182 drawState
|= wxCONTROL_DISABLED
;
1184 if ( !m_bmpNormal
.Ok() )
1186 // Need to clear button background even if m_btn is present
1191 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1192 bgCol
= GetParent()->GetBackgroundColour();
1194 bgCol
= GetBackgroundColour();
1198 dc
.DrawRectangle(rect
);
1201 // Draw standard button
1202 wxRendererNative::Get().DrawComboBoxDropButton(this,
1214 pBmp
= &m_bmpDisabled
;
1215 else if ( m_btnState
& wxCONTROL_PRESSED
)
1216 pBmp
= &m_bmpPressed
;
1217 else if ( m_btnState
& wxCONTROL_CURRENT
)
1220 pBmp
= &m_bmpNormal
;
1222 if ( m_blankButtonBg
)
1224 // If using blank button background, we need to clear its background
1225 // with button face colour instead of colour for rest of the control.
1228 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1229 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1232 dc
.DrawRectangle(rect
);
1235 wxRendererNative::Get().DrawPushButton(this,
1244 // Need to clear button background even if m_btn is present
1245 // (assume non-button background was cleared just before this call so brushes are good)
1247 dc
.DrawRectangle(rect
);
1250 // Draw bitmap centered in drawRect
1251 dc
.DrawBitmap(*pBmp
,
1252 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1253 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1258 void wxComboCtrlBase::RecalcAndRefresh()
1262 wxSizeEvent
evt(GetSize(),GetId());
1263 GetEventHandler()->ProcessEvent(evt
);
1268 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1270 // If size is larger, recalculate double buffer bitmap
1271 if ( !gs_doubleBuffer
||
1272 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1273 sz
.y
> gs_doubleBuffer
->GetHeight() )
1275 delete gs_doubleBuffer
;
1276 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1278 return *gs_doubleBuffer
;
1281 // ----------------------------------------------------------------------------
1282 // miscellaneous event handlers
1283 // ----------------------------------------------------------------------------
1285 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1287 // Change event id and relay it forward
1288 event
.SetId(GetId());
1292 // call if cursor is on button area or mouse is captured for the button
1293 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1296 int type
= event
.GetEventType();
1298 if ( type
== wxEVT_MOTION
)
1300 if ( flags
& wxCC_MF_ON_BUTTON
)
1302 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1304 // Mouse hover begins
1305 m_btnState
|= wxCONTROL_CURRENT
;
1306 if ( HasCapture() ) // Retain pressed state.
1307 m_btnState
|= wxCONTROL_PRESSED
;
1311 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1314 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1318 else if ( type
== wxEVT_LEFT_DOWN
)
1320 // Only accept event if it wasn't right after popup dismiss
1321 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1323 // Need to test this, because it might be outside.
1324 if ( flags
& wxCC_MF_ON_BUTTON
)
1326 m_btnState
|= wxCONTROL_PRESSED
;
1329 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1332 // If showing popup now, do not capture mouse or there will be interference
1341 else if ( type
== wxEVT_LEFT_UP
)
1344 // Only accept event if mouse was left-press was previously accepted
1348 if ( m_btnState
& wxCONTROL_PRESSED
)
1350 // If mouse was inside, fire the click event.
1351 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1353 if ( flags
& wxCC_MF_ON_BUTTON
)
1357 m_btnState
&= ~(wxCONTROL_PRESSED
);
1361 else if ( type
== wxEVT_LEAVE_WINDOW
)
1363 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1365 m_btnState
&= ~(wxCONTROL_CURRENT
);
1368 if ( !m_isPopupShown
)
1370 m_btnState
&= ~(wxCONTROL_PRESSED
);
1381 // Conversion to double-clicks and some basic filtering
1382 // returns true if event was consumed or filtered
1383 //bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
1384 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1387 wxLongLong t
= ::wxGetLocalTimeMillis();
1388 int evtType
= event
.GetEventType();
1391 // Generate our own double-clicks
1392 // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
1393 if ( (m_windowStyle
& wxCC_SPECIAL_DCLICK
) &&
1395 //!(handlerFlags & wxCC_MF_ON_BUTTON) )
1396 !(flags
& wxCC_MF_ON_BUTTON
) )
1398 if ( evtType
== wxEVT_LEFT_DOWN
)
1400 // Set value to avoid up-events without corresponding downs
1401 m_downReceived
= true;
1403 else if ( evtType
== wxEVT_LEFT_DCLICK
)
1405 // We'll make our own double-clicks
1407 event
.SetEventType(0);
1410 else if ( evtType
== wxEVT_LEFT_UP
)
1412 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
1414 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
1416 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
1418 //type = wxEVT_LEFT_DCLICK;
1419 event
.SetEventType(wxEVT_LEFT_DCLICK
);
1420 m_timeLastMouseUp
= 1;
1424 m_timeLastMouseUp
= t
;
1427 //m_downReceived = false;
1432 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1433 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1435 event
.SetEventType(0);
1442 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1444 int evtType
= event
.GetEventType();
1446 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1447 (m_windowStyle
& wxCB_READONLY
) )
1449 if ( m_isPopupShown
)
1452 // Normally do nothing - evt handler should close it for us
1453 #elif !USE_TRANSIENT_POPUP
1454 // Click here always hides the popup.
1460 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1462 // In read-only mode, clicking the text is the
1463 // same as clicking the button.
1466 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1468 //if ( m_popupInterface->CycleValue() )
1470 if ( m_popupInterface
)
1471 m_popupInterface
->OnComboDoubleClick();
1476 if ( m_isPopupShown
)
1478 // relay (some) mouse events to the popup
1479 if ( evtType
== wxEVT_MOUSEWHEEL
)
1480 m_popup
->AddPendingEvent(event
);
1486 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& )
1488 // First click is the first part of double-click
1489 // Some platforms don't generate down-less mouse up-event
1490 // (Windows does, GTK+2 doesn't), so that's why we have
1492 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
1499 // no need to check for m_widthCustomPaint - that
1500 // area never gets special handling when selected
1501 // (in writable mode, that is)
1505 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1508 // indentation may also have changed
1509 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1510 m_absIndent
= GetNativeTextIndent();
1514 // ----------------------------------------------------------------------------
1516 // ----------------------------------------------------------------------------
1518 // Create popup window and the child control
1519 void wxComboCtrlBase::CreatePopup()
1521 wxComboPopup
* popupInterface
= m_popupInterface
;
1525 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1527 popupInterface
->Create(m_winPopup
);
1528 m_popup
= popup
= popupInterface
->GetControl();
1530 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1531 popup
->PushEventHandler( m_popupExtraHandler
);
1533 // This may be helpful on some platforms
1534 // (eg. it bypasses a wxGTK popupwindow bug where
1535 // window is not initially hidden when it should be)
1538 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1541 // Destroy popup window and the child control
1542 void wxComboCtrlBase::DestroyPopup()
1545 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1547 delete m_popupExtraHandler
;
1551 delete m_popupInterface
;
1554 m_winPopup
->Destroy();
1556 m_popupInterface
= (wxComboPopup
*) NULL
;
1557 m_winPopup
= (wxWindow
*) NULL
;
1558 m_popup
= (wxWindow
*) NULL
;
1561 void wxComboCtrlBase::SetPopupControl( wxComboPopup
* iface
)
1563 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1567 iface
->InitBase(this);
1570 m_popupInterface
= iface
;
1572 if ( !iface
->LazyCreate() )
1578 m_popup
= (wxWindow
*) NULL
;
1581 // This must be done after creation
1582 if ( m_valueString
.length() )
1584 iface
->SetStringValue(m_valueString
);
1589 // Ensures there is atleast the default popup
1590 void wxComboCtrlBase::EnsurePopupControl()
1592 if ( !m_popupInterface
)
1593 SetPopupControl(NULL
);
1596 void wxComboCtrlBase::OnButtonClick()
1598 // Derived classes can override this method for totally custom
1603 void wxComboCtrlBase::ShowPopup()
1605 EnsurePopupControl();
1606 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1610 // Space above and below
1616 wxSize ctrlSz
= GetSize();
1618 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1619 scrPos
= GetParent()->ClientToScreen(GetPosition());
1621 spaceAbove
= scrPos
.y
;
1622 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1624 maxHeightPopup
= spaceBelow
;
1625 if ( spaceAbove
> spaceBelow
)
1626 maxHeightPopup
= spaceAbove
;
1629 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1631 if ( widthPopup
< m_widthMinPopup
)
1632 widthPopup
= m_widthMinPopup
;
1634 wxWindow
* winPopup
= m_winPopup
;
1637 // Need to disable tab traversal of parent
1639 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1640 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1641 // that if transient popup is open, then tab traversal is to be ignored.
1642 // However, I think this code would still be needed for cases where
1643 // transient popup doesn't work yet (wxWinCE?).
1644 wxWindow
* parent
= GetParent();
1645 int parentFlags
= parent
->GetWindowStyle();
1646 if ( parentFlags
& wxTAB_TRAVERSAL
)
1648 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1649 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1655 winPopup
= m_winPopup
;
1663 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1665 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1666 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1669 popup
->SetSize(adjustedSize
);
1671 m_popupInterface
->OnPopup();
1674 // Reposition and resize popup window
1677 wxSize szp
= popup
->GetSize();
1680 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1682 // Default anchor is wxLEFT
1683 int anchorSide
= m_anchorSide
;
1685 anchorSide
= wxLEFT
;
1687 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1688 int leftX
= scrPos
.x
- m_extLeft
;
1689 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1691 // If there is not enough horizontal space, anchor on the other side.
1692 // If there is no space even then, place the popup at x 0.
1693 if ( anchorSide
== wxRIGHT
)
1697 if ( (leftX
+szp
.x
) < screenWidth
)
1698 anchorSide
= wxLEFT
;
1705 if ( (leftX
+szp
.x
) >= screenWidth
)
1708 anchorSide
= wxRIGHT
;
1714 // Select x coordinate according to the anchor side
1715 if ( anchorSide
== wxRIGHT
)
1717 else if ( anchorSide
== wxLEFT
)
1722 if ( spaceBelow
< szp
.y
)
1724 popupY
= scrPos
.y
- szp
.y
;
1728 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1729 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1731 // Some platforms (GTK) may need these two to be separate
1732 winPopup
->SetSize( szp
.x
, szp
.y
);
1733 winPopup
->Move( popupX
, popupY
);
1735 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1739 // Set string selection (must be this way instead of SetStringSelection)
1742 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1743 m_text
->SelectAll();
1745 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1749 // This is neede since focus/selection indication may change when popup is shown
1753 // This must be after SetStringValue
1754 m_isPopupShown
= true;
1757 #if USE_TRANSIENT_POPUP
1758 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1763 #if INSTALL_TOPLEV_HANDLER
1764 // Put top level window event handler into place
1765 if ( !m_toplevEvtHandler
)
1766 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1768 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1770 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1771 toplev
->PushEventHandler( m_toplevEvtHandler
);
1776 void wxComboCtrlBase::OnPopupDismiss()
1778 // Just in case, avoid double dismiss
1779 if ( !m_isPopupShown
)
1782 // *Must* set this before focus etc.
1783 m_isPopupShown
= false;
1785 // Inform popup control itself
1786 m_popupInterface
->OnDismiss();
1788 if ( m_popupExtraHandler
)
1789 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1791 #if INSTALL_TOPLEV_HANDLER
1792 // Remove top level window event handler
1793 if ( m_toplevEvtHandler
)
1795 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1797 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1801 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1803 // If cursor not on dropdown button, then clear its state
1804 // (technically not required by all ports, but do it for all just in case)
1805 if ( !m_btnArea
.Inside(ScreenToClient(::wxGetMousePosition())) )
1808 // Return parent's tab traversal flag.
1809 // See ShowPopup for notes.
1810 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1812 wxWindow
* parent
= GetParent();
1813 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1814 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1817 // refresh control (necessary even if m_text)
1826 void wxComboCtrlBase::HidePopup()
1828 // Should be able to call this without popup interface
1829 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1830 if ( !m_isPopupShown
)
1833 // transfer value and show it in textctrl, if any
1834 SetValue( m_popupInterface
->GetStringValue() );
1836 #if USE_TRANSIENT_POPUP
1837 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1845 // ----------------------------------------------------------------------------
1846 // customization methods
1847 // ----------------------------------------------------------------------------
1849 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1850 int side
, int spacingX
)
1855 m_btnSpacingX
= spacingX
;
1860 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1862 const wxBitmap
& bmpPressed
,
1863 const wxBitmap
& bmpHover
,
1864 const wxBitmap
& bmpDisabled
)
1866 m_bmpNormal
= bmpNormal
;
1867 m_blankButtonBg
= blankButtonBg
;
1869 if ( bmpPressed
.Ok() )
1870 m_bmpPressed
= bmpPressed
;
1872 m_bmpPressed
= bmpNormal
;
1874 if ( bmpHover
.Ok() )
1875 m_bmpHover
= bmpHover
;
1877 m_bmpHover
= bmpNormal
;
1879 if ( bmpDisabled
.Ok() )
1880 m_bmpDisabled
= bmpDisabled
;
1882 m_bmpDisabled
= bmpNormal
;
1887 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1891 // move textctrl accordingly
1892 wxRect r
= m_text
->GetRect();
1893 int inc
= width
- m_widthCustomPaint
;
1896 m_text
->SetSize( r
);
1899 m_widthCustomPaint
= width
;
1904 void wxComboCtrlBase::SetTextIndent( int indent
)
1908 m_absIndent
= GetNativeTextIndent();
1909 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1913 m_absIndent
= indent
;
1914 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1920 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1922 return DEFAULT_TEXT_INDENT
;
1925 // ----------------------------------------------------------------------------
1926 // methods forwarded to wxTextCtrl
1927 // ----------------------------------------------------------------------------
1929 wxString
wxComboCtrlBase::GetValue() const
1932 return m_text
->GetValue();
1933 return m_valueString
;
1936 void wxComboCtrlBase::SetValue(const wxString
& value
)
1940 m_text
->SetValue(value
);
1941 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1942 m_text
->SelectAll();
1945 m_valueString
= value
;
1949 // Since wxComboPopup may want to paint the combo as well, we need
1950 // to set the string value here (as well as sometimes in ShowPopup).
1951 if ( m_valueString
!= value
&& m_popupInterface
)
1953 m_popupInterface
->SetStringValue(value
);
1957 // In this SetValue variant wxComboPopup::SetStringValue is not called
1958 void wxComboCtrlBase::SetText(const wxString
& value
)
1960 // Unlike in SetValue(), this must be called here or
1961 // the behaviour will no be consistent in readonlys.
1962 EnsurePopupControl();
1964 m_valueString
= value
;
1969 void wxComboCtrlBase::Copy()
1975 void wxComboCtrlBase::Cut()
1981 void wxComboCtrlBase::Paste()
1987 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1990 m_text
->SetInsertionPoint(pos
);
1993 void wxComboCtrlBase::SetInsertionPointEnd()
1996 m_text
->SetInsertionPointEnd();
1999 long wxComboCtrlBase::GetInsertionPoint() const
2002 return m_text
->GetInsertionPoint();
2007 long wxComboCtrlBase::GetLastPosition() const
2010 return m_text
->GetLastPosition();
2015 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2018 m_text
->Replace(from
, to
, value
);
2021 void wxComboCtrlBase::Remove(long from
, long to
)
2024 m_text
->Remove(from
, to
);
2027 void wxComboCtrlBase::SetSelection(long from
, long to
)
2030 m_text
->SetSelection(from
, to
);
2033 void wxComboCtrlBase::Undo()
2039 #endif // wxUSE_COMBOCTRL