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 200
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;
641 m_btnWid
= m_btnHei
= -1;
649 m_timeCanAcceptClick
= 0;
652 bool wxComboCtrlBase::Create(wxWindow
*parent
,
654 const wxString
& value
,
658 const wxValidator
& validator
,
659 const wxString
& name
)
661 if ( !wxControl::Create(parent
,
665 style
| wxWANTS_CHARS
,
670 m_valueString
= value
;
674 m_absIndent
= GetNativeTextIndent();
676 m_iFlags
|= wxCC_IFLAG_CREATED
;
678 // If x and y indicate valid size, wxSizeEvent won't be
679 // emitted automatically, so we need to add artifical one.
680 if ( size
.x
> 0 && size
.y
> 0 )
682 wxSizeEvent
evt(size
,GetId());
683 GetEventHandler()->AddPendingEvent(evt
);
689 void wxComboCtrlBase::InstallInputHandlers()
693 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
694 m_text
->PushEventHandler(m_textEvtHandler
);
699 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
701 if ( !(m_windowStyle
& wxCB_READONLY
) )
703 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
704 // not used by the wxPropertyGrid and therefore the tab is processed by
705 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
706 // navigation event is then sent to the wrong window.
707 style
|= wxTE_PROCESS_TAB
;
709 if ( HasFlag(wxTE_PROCESS_ENTER
) )
710 style
|= wxTE_PROCESS_ENTER
;
712 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
713 wxDefaultPosition
, wxDefaultSize
,
716 // This is required for some platforms (GTK+ atleast)
717 m_text
->SetSizeHints(2,4);
721 void wxComboCtrlBase::OnThemeChange()
723 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
726 wxComboCtrlBase::~wxComboCtrlBase()
731 delete gs_doubleBuffer
;
732 gs_doubleBuffer
= (wxBitmap
*) NULL
;
734 #if INSTALL_TOPLEV_HANDLER
735 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
736 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
742 m_text
->RemoveEventHandler(m_textEvtHandler
);
744 delete m_textEvtHandler
;
748 // ----------------------------------------------------------------------------
750 // ----------------------------------------------------------------------------
752 // Recalculates button and textctrl areas
753 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
755 wxSize sz
= GetClientSize();
756 int customBorder
= m_widthCustomBorder
;
757 int btnBorder
; // border for button only
759 // check if button should really be outside the border: we'll do it it if
760 // its platform default or bitmap+pushbutton background is used, but not if
761 // there is vertical size adjustment or horizontal spacing.
762 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
763 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
764 m_btnSpacingX
== 0 &&
767 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
772 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
773 btnBorder
= customBorder
;
776 // Defaul indentation
777 if ( m_absIndent
< 0 )
778 m_absIndent
= GetNativeTextIndent();
780 int butWidth
= btnWidth
;
783 butWidth
= m_btnWidDefault
;
785 m_btnWidDefault
= butWidth
;
790 int butHeight
= sz
.y
- btnBorder
*2;
792 // Adjust button width
797 // Adjust button width to match aspect ratio
798 // (but only if control is smaller than best size).
799 int bestHeight
= GetBestSize().y
;
800 int height
= GetSize().y
;
802 if ( height
< bestHeight
)
804 // Make very small buttons square, as it makes
805 // them accommodate arrow image better and still
808 butWidth
= (height
*butWidth
)/bestHeight
;
810 butWidth
= butHeight
;
814 // Adjust button height
816 butHeight
= m_btnHei
;
818 // Use size of normal bitmap if...
821 // button width is set to default and blank button bg is not drawn
822 if ( m_bmpNormal
.Ok() )
824 int bmpReqWidth
= m_bmpNormal
.GetWidth();
825 int bmpReqHeight
= m_bmpNormal
.GetHeight();
827 // If drawing blank button background, we need to add some margin.
828 if ( m_blankButtonBg
)
830 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
831 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
834 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
835 butWidth
= bmpReqWidth
;
836 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
837 butHeight
= bmpReqHeight
;
839 // Need to fix height?
840 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
842 int newY
= butHeight
+(customBorder
*2);
843 SetClientSize(wxDefaultCoord
,newY
);
848 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
850 m_btnSize
.x
= butWidth
;
851 m_btnSize
.y
= butHeight
;
853 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
854 m_btnArea
.y
= btnBorder
;
855 m_btnArea
.width
= butAreaWid
;
856 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
858 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
859 m_tcArea
.y
= customBorder
;
860 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
861 m_tcArea
.height
= sz
.y
- (customBorder
*2);
866 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
867 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
872 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
877 wxSize sz
= GetClientSize();
878 int customBorder
= m_widthCustomBorder
;
880 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
883 int tcSizeY
= m_text
->GetBestSize().y
;
884 int diff
= sz
.y
- tcSizeY
;
885 int y
= textCtrlYAdjust
+ (diff
/2);
887 if ( y
< customBorder
)
890 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
892 m_tcArea
.width
- COMBO_MARGIN
-
893 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
896 // Make sure textctrl doesn't exceed the bottom custom border
897 wxSize tsz
= m_text
->GetSize();
898 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
901 tsz
.y
= tsz
.y
- diff
- 1;
902 m_text
->SetSize(tsz
);
907 m_text
->SetSize( m_tcArea
.x
,
909 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
914 wxSize
wxComboCtrlBase::DoGetBestSize() const
916 wxSize
sizeText(150,0);
919 sizeText
= m_text
->GetBestSize();
921 // TODO: Better method to calculate close-to-native control height.
925 fhei
= (m_font
.GetPointSize()*2) + 5;
926 else if ( wxNORMAL_FONT
->Ok() )
927 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
929 fhei
= sizeText
.y
+ 4;
931 // Need to force height to accomodate bitmap?
932 int btnSizeY
= m_btnSize
.y
;
933 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
936 // Control height doesn't depend on border
939 int border = m_windowStyle & wxBORDER_MASK;
940 if ( border == wxSIMPLE_BORDER )
942 else if ( border == wxNO_BORDER )
943 fhei += (m_widthCustomBorder*2);
954 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
961 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
966 // defined by actual wxComboCtrls
972 // ----------------------------------------------------------------------------
973 // standard operations
974 // ----------------------------------------------------------------------------
976 bool wxComboCtrlBase::Enable(bool enable
)
978 if ( !wxControl::Enable(enable
) )
982 m_btn
->Enable(enable
);
984 m_text
->Enable(enable
);
989 bool wxComboCtrlBase::Show(bool show
)
991 if ( !wxControl::Show(show
) )
1003 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1005 if ( !wxControl::SetFont(font
) )
1009 m_text
->SetFont(font
);
1015 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1017 wxControl::DoSetToolTip(tooltip
);
1019 // Set tool tip for button and text box
1022 const wxString
&tip
= tooltip
->GetTip();
1023 if ( m_text
) m_text
->SetToolTip(tip
);
1024 if ( m_btn
) m_btn
->SetToolTip(tip
);
1028 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1029 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1032 #endif // wxUSE_TOOLTIPS
1034 // ----------------------------------------------------------------------------
1036 // ----------------------------------------------------------------------------
1038 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1039 // prepare combo box background on area in a way typical on platform
1040 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1042 wxSize sz
= GetClientSize();
1044 bool isFocused
; // also selected
1046 // For smaller size control (and for disabled background) use less spacing
1050 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1053 isEnabled
= IsEnabled();
1054 isFocused
= ShouldDrawFocus();
1056 // Windows-style: for smaller size control (and for disabled background) use less spacing
1057 focusSpacingX
= isEnabled
? 2 : 1;
1058 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1062 // Drawing a list item
1063 isEnabled
= true; // they are never disabled
1064 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1070 // Set the background sub-rectangle for selection, disabled etc
1071 wxRect
selRect(rect
);
1072 selRect
.y
+= focusSpacingY
;
1073 selRect
.height
-= (focusSpacingY
*2);
1077 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1078 wcp
+= m_widthCustomPaint
;
1080 selRect
.x
+= wcp
+ focusSpacingX
;
1081 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1087 // If popup is hidden and this control is focused,
1088 // then draw the focus-indicator (selbgcolor background etc.).
1091 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1092 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1096 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1097 bgCol
= GetBackgroundColour();
1102 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1103 bgCol
= GetBackgroundColour();
1106 dc
.SetBrush( bgCol
);
1108 dc
.DrawRectangle( selRect
);
1110 // Don't clip exactly to the selection rectangle so we can draw
1111 // to the non-selected area in front of it.
1112 wxRect
clipRect(rect
.x
,rect
.y
,
1113 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1114 dc
.SetClippingRegion(clipRect
);
1117 // Save the library size a bit for platforms that re-implement this.
1118 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1123 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1125 int drawState
= m_btnState
;
1128 if ( m_isPopupShown
)
1129 drawState
|= wxCONTROL_PRESSED
;
1132 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1133 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1137 // Make sure area is not larger than the control
1138 if ( drawRect
.y
< rect
.y
)
1139 drawRect
.y
= rect
.y
;
1140 if ( drawRect
.height
> rect
.height
)
1141 drawRect
.height
= rect
.height
;
1143 bool enabled
= IsEnabled();
1146 drawState
|= wxCONTROL_DISABLED
;
1148 if ( !m_bmpNormal
.Ok() )
1150 // Need to clear button background even if m_btn is present
1155 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1156 bgCol
= GetParent()->GetBackgroundColour();
1158 bgCol
= GetBackgroundColour();
1162 dc
.DrawRectangle(rect
);
1165 // Draw standard button
1166 wxRendererNative::Get().DrawComboBoxDropButton(this,
1178 pBmp
= &m_bmpDisabled
;
1179 else if ( m_btnState
& wxCONTROL_PRESSED
)
1180 pBmp
= &m_bmpPressed
;
1181 else if ( m_btnState
& wxCONTROL_CURRENT
)
1184 pBmp
= &m_bmpNormal
;
1186 if ( m_blankButtonBg
)
1188 // If using blank button background, we need to clear its background
1189 // with button face colour instead of colour for rest of the control.
1192 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1193 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1196 dc
.DrawRectangle(rect
);
1199 wxRendererNative::Get().DrawPushButton(this,
1208 // Need to clear button background even if m_btn is present
1209 // (assume non-button background was cleared just before this call so brushes are good)
1211 dc
.DrawRectangle(rect
);
1214 // Draw bitmap centered in drawRect
1215 dc
.DrawBitmap(*pBmp
,
1216 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1217 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1222 void wxComboCtrlBase::RecalcAndRefresh()
1226 wxSizeEvent
evt(GetSize(),GetId());
1227 GetEventHandler()->ProcessEvent(evt
);
1232 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1234 // If size is larger, recalculate double buffer bitmap
1235 if ( !gs_doubleBuffer
||
1236 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1237 sz
.y
> gs_doubleBuffer
->GetHeight() )
1239 delete gs_doubleBuffer
;
1240 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1242 return *gs_doubleBuffer
;
1245 // ----------------------------------------------------------------------------
1246 // miscellaneous event handlers
1247 // ----------------------------------------------------------------------------
1249 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1251 // Change event id, object and string before relaying it forward
1252 event
.SetId(GetId());
1253 wxString s
= event
.GetString();
1254 event
.SetEventObject(this);
1259 // call if cursor is on button area or mouse is captured for the button
1260 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1263 int type
= event
.GetEventType();
1265 if ( type
== wxEVT_MOTION
)
1267 if ( flags
& wxCC_MF_ON_BUTTON
)
1269 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1271 // Mouse hover begins
1272 m_btnState
|= wxCONTROL_CURRENT
;
1273 if ( HasCapture() ) // Retain pressed state.
1274 m_btnState
|= wxCONTROL_PRESSED
;
1278 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1281 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1285 else if ( type
== wxEVT_LEFT_DOWN
)
1287 // Only accept event if it wasn't right after popup dismiss
1288 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1290 // Need to test this, because it might be outside.
1291 if ( flags
& wxCC_MF_ON_BUTTON
)
1293 m_btnState
|= wxCONTROL_PRESSED
;
1296 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1299 // If showing popup now, do not capture mouse or there will be interference
1308 else if ( type
== wxEVT_LEFT_UP
)
1311 // Only accept event if mouse was left-press was previously accepted
1315 if ( m_btnState
& wxCONTROL_PRESSED
)
1317 // If mouse was inside, fire the click event.
1318 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1320 if ( flags
& wxCC_MF_ON_BUTTON
)
1324 m_btnState
&= ~(wxCONTROL_PRESSED
);
1328 else if ( type
== wxEVT_LEAVE_WINDOW
)
1330 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1332 m_btnState
&= ~(wxCONTROL_CURRENT
);
1335 if ( !m_isPopupShown
)
1337 m_btnState
&= ~(wxCONTROL_PRESSED
);
1348 // returns true if event was consumed or filtered
1349 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1350 int WXUNUSED(flags
) )
1352 wxLongLong t
= ::wxGetLocalTimeMillis();
1353 int evtType
= event
.GetEventType();
1355 #if !USE_TRANSIENT_POPUP
1356 if ( m_isPopupShown
&&
1357 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1364 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1365 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1367 event
.SetEventType(0);
1374 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1376 int evtType
= event
.GetEventType();
1378 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1379 (m_windowStyle
& wxCB_READONLY
) )
1381 if ( m_isPopupShown
)
1384 // Normally do nothing - evt handler should close it for us
1385 #elif !USE_TRANSIENT_POPUP
1386 // Click here always hides the popup.
1392 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1394 // In read-only mode, clicking the text is the
1395 // same as clicking the button.
1398 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1400 //if ( m_popupInterface->CycleValue() )
1402 if ( m_popupInterface
)
1403 m_popupInterface
->OnComboDoubleClick();
1408 if ( m_isPopupShown
)
1410 // relay (some) mouse events to the popup
1411 if ( evtType
== wxEVT_MOUSEWHEEL
)
1412 m_popup
->AddPendingEvent(event
);
1418 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1420 if ( IsPopupShown() )
1422 // pass it to the popped up control
1423 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1427 int keycode
= event
.GetKeyCode();
1429 if ( keycode
== WXK_TAB
)
1431 wxNavigationKeyEvent evt
;
1432 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1433 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1434 : wxNavigationKeyEvent::IsBackward
));
1435 evt
.SetEventObject(this);
1436 GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1440 if ( IsKeyPopupToggle(event
) )
1446 int comboStyle
= GetWindowStyle();
1447 wxComboPopup
* popupInterface
= GetPopupControl();
1449 if ( !popupInterface
)
1455 if ( (comboStyle
& wxCB_READONLY
) ||
1456 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1458 popupInterface
->OnComboKeyEvent(event
);
1465 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1467 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1469 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1476 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1479 // indentation may also have changed
1480 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1481 m_absIndent
= GetNativeTextIndent();
1485 // ----------------------------------------------------------------------------
1487 // ----------------------------------------------------------------------------
1489 // Create popup window and the child control
1490 void wxComboCtrlBase::CreatePopup()
1492 wxComboPopup
* popupInterface
= m_popupInterface
;
1496 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1498 popupInterface
->Create(m_winPopup
);
1499 m_popup
= popup
= popupInterface
->GetControl();
1501 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1502 popup
->PushEventHandler( m_popupExtraHandler
);
1504 // This may be helpful on some platforms
1505 // (eg. it bypasses a wxGTK popupwindow bug where
1506 // window is not initially hidden when it should be)
1509 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1512 // Destroy popup window and the child control
1513 void wxComboCtrlBase::DestroyPopup()
1518 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1520 delete m_popupExtraHandler
;
1522 delete m_popupInterface
;
1525 m_winPopup
->Destroy();
1527 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1528 m_popupInterface
= (wxComboPopup
*) NULL
;
1529 m_winPopup
= (wxWindow
*) NULL
;
1530 m_popup
= (wxWindow
*) NULL
;
1533 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1535 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1539 iface
->InitBase(this);
1542 m_popupInterface
= iface
;
1544 if ( !iface
->LazyCreate() )
1550 m_popup
= (wxWindow
*) NULL
;
1553 // This must be done after creation
1554 if ( m_valueString
.length() )
1556 iface
->SetStringValue(m_valueString
);
1561 // Ensures there is atleast the default popup
1562 void wxComboCtrlBase::EnsurePopupControl()
1564 if ( !m_popupInterface
)
1565 SetPopupControl(NULL
);
1568 void wxComboCtrlBase::OnButtonClick()
1570 // Derived classes can override this method for totally custom
1575 void wxComboCtrlBase::ShowPopup()
1577 EnsurePopupControl();
1578 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1582 // Space above and below
1588 wxSize ctrlSz
= GetSize();
1590 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1591 scrPos
= GetParent()->ClientToScreen(GetPosition());
1593 spaceAbove
= scrPos
.y
;
1594 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1596 maxHeightPopup
= spaceBelow
;
1597 if ( spaceAbove
> spaceBelow
)
1598 maxHeightPopup
= spaceAbove
;
1601 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1603 if ( widthPopup
< m_widthMinPopup
)
1604 widthPopup
= m_widthMinPopup
;
1606 wxWindow
* winPopup
= m_winPopup
;
1609 // Need to disable tab traversal of parent
1611 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1612 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1613 // that if transient popup is open, then tab traversal is to be ignored.
1614 // However, I think this code would still be needed for cases where
1615 // transient popup doesn't work yet (wxWinCE?).
1616 wxWindow
* parent
= GetParent();
1617 int parentFlags
= parent
->GetWindowStyle();
1618 if ( parentFlags
& wxTAB_TRAVERSAL
)
1620 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1621 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1627 winPopup
= m_winPopup
;
1635 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1637 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1638 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1641 popup
->SetSize(adjustedSize
);
1643 m_popupInterface
->OnPopup();
1646 // Reposition and resize popup window
1649 wxSize szp
= popup
->GetSize();
1652 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1654 // Default anchor is wxLEFT
1655 int anchorSide
= m_anchorSide
;
1657 anchorSide
= wxLEFT
;
1659 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1660 int leftX
= scrPos
.x
- m_extLeft
;
1661 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1663 // If there is not enough horizontal space, anchor on the other side.
1664 // If there is no space even then, place the popup at x 0.
1665 if ( anchorSide
== wxRIGHT
)
1669 if ( (leftX
+szp
.x
) < screenWidth
)
1670 anchorSide
= wxLEFT
;
1677 if ( (leftX
+szp
.x
) >= screenWidth
)
1680 anchorSide
= wxRIGHT
;
1686 // Select x coordinate according to the anchor side
1687 if ( anchorSide
== wxRIGHT
)
1689 else if ( anchorSide
== wxLEFT
)
1694 if ( spaceBelow
< szp
.y
)
1696 popupY
= scrPos
.y
- szp
.y
;
1700 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1701 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1703 // Some platforms (GTK) may need these two to be separate
1704 winPopup
->SetSize( szp
.x
, szp
.y
);
1705 winPopup
->Move( popupX
, popupY
);
1707 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1711 // Set string selection (must be this way instead of SetStringSelection)
1714 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1715 m_text
->SelectAll();
1717 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1721 // This is neede since focus/selection indication may change when popup is shown
1725 // This must be after SetStringValue
1726 m_isPopupShown
= true;
1729 #if USE_TRANSIENT_POPUP
1730 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1735 #if INSTALL_TOPLEV_HANDLER
1736 // Put top level window event handler into place
1737 if ( !m_toplevEvtHandler
)
1738 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1740 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1742 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1743 toplev
->PushEventHandler( m_toplevEvtHandler
);
1748 void wxComboCtrlBase::OnPopupDismiss()
1750 // Just in case, avoid double dismiss
1751 if ( !m_isPopupShown
)
1754 // *Must* set this before focus etc.
1755 m_isPopupShown
= false;
1757 // Inform popup control itself
1758 m_popupInterface
->OnDismiss();
1760 if ( m_popupExtraHandler
)
1761 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1763 #if INSTALL_TOPLEV_HANDLER
1764 // Remove top level window event handler
1765 if ( m_toplevEvtHandler
)
1767 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1769 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1773 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1775 // If cursor not on dropdown button, then clear its state
1776 // (technically not required by all ports, but do it for all just in case)
1777 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1780 // Return parent's tab traversal flag.
1781 // See ShowPopup for notes.
1782 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1784 wxWindow
* parent
= GetParent();
1785 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1786 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1789 // refresh control (necessary even if m_text)
1798 void wxComboCtrlBase::HidePopup()
1800 // Should be able to call this without popup interface
1801 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1802 if ( !m_isPopupShown
)
1805 // transfer value and show it in textctrl, if any
1806 SetValue( m_popupInterface
->GetStringValue() );
1808 #if USE_TRANSIENT_POPUP
1809 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1817 // ----------------------------------------------------------------------------
1818 // customization methods
1819 // ----------------------------------------------------------------------------
1821 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1822 int side
, int spacingX
)
1827 m_btnSpacingX
= spacingX
;
1832 wxSize
wxComboCtrlBase::GetButtonSize()
1834 if ( m_btnSize
.x
> 0 )
1837 wxSize
retSize(m_btnWid
,m_btnHei
);
1839 // Need to call CalculateAreas now if button size is
1840 // is not explicitly specified.
1841 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
1845 retSize
= m_btnSize
;
1851 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1853 const wxBitmap
& bmpPressed
,
1854 const wxBitmap
& bmpHover
,
1855 const wxBitmap
& bmpDisabled
)
1857 m_bmpNormal
= bmpNormal
;
1858 m_blankButtonBg
= blankButtonBg
;
1860 if ( bmpPressed
.Ok() )
1861 m_bmpPressed
= bmpPressed
;
1863 m_bmpPressed
= bmpNormal
;
1865 if ( bmpHover
.Ok() )
1866 m_bmpHover
= bmpHover
;
1868 m_bmpHover
= bmpNormal
;
1870 if ( bmpDisabled
.Ok() )
1871 m_bmpDisabled
= bmpDisabled
;
1873 m_bmpDisabled
= bmpNormal
;
1878 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1882 // move textctrl accordingly
1883 wxRect r
= m_text
->GetRect();
1884 int inc
= width
- m_widthCustomPaint
;
1887 m_text
->SetSize( r
);
1890 m_widthCustomPaint
= width
;
1895 void wxComboCtrlBase::SetTextIndent( int indent
)
1899 m_absIndent
= GetNativeTextIndent();
1900 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1904 m_absIndent
= indent
;
1905 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1911 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1913 return DEFAULT_TEXT_INDENT
;
1916 // ----------------------------------------------------------------------------
1917 // methods forwarded to wxTextCtrl
1918 // ----------------------------------------------------------------------------
1920 wxString
wxComboCtrlBase::GetValue() const
1923 return m_text
->GetValue();
1924 return m_valueString
;
1927 void wxComboCtrlBase::SetValue(const wxString
& value
)
1931 m_text
->SetValue(value
);
1932 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1933 m_text
->SelectAll();
1936 m_valueString
= value
;
1940 // Since wxComboPopup may want to paint the combo as well, we need
1941 // to set the string value here (as well as sometimes in ShowPopup).
1942 if ( m_valueString
!= value
&& m_popupInterface
)
1944 m_popupInterface
->SetStringValue(value
);
1948 // In this SetValue variant wxComboPopup::SetStringValue is not called
1949 void wxComboCtrlBase::SetText(const wxString
& value
)
1951 // Unlike in SetValue(), this must be called here or
1952 // the behaviour will no be consistent in readonlys.
1953 EnsurePopupControl();
1955 m_valueString
= value
;
1960 void wxComboCtrlBase::Copy()
1966 void wxComboCtrlBase::Cut()
1972 void wxComboCtrlBase::Paste()
1978 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1981 m_text
->SetInsertionPoint(pos
);
1984 void wxComboCtrlBase::SetInsertionPointEnd()
1987 m_text
->SetInsertionPointEnd();
1990 long wxComboCtrlBase::GetInsertionPoint() const
1993 return m_text
->GetInsertionPoint();
1998 long wxComboCtrlBase::GetLastPosition() const
2001 return m_text
->GetLastPosition();
2006 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2009 m_text
->Replace(from
, to
, value
);
2012 void wxComboCtrlBase::Remove(long from
, long to
)
2015 m_text
->Remove(from
, to
);
2018 void wxComboCtrlBase::SetSelection(long from
, long to
)
2021 m_text
->SetSelection(from
, to
);
2024 void wxComboCtrlBase::Undo()
2030 #endif // wxUSE_COMBOCTRL