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();
722 void wxComboCtrlBase::InstallInputHandlers( bool alsoTextCtrl
)
724 if ( m_text
&& alsoTextCtrl
)
726 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
727 m_text
->PushEventHandler(m_textEvtHandler
);
730 wxComboBoxExtraInputHandler
* inputHandler
= new wxComboBoxExtraInputHandler(this);
731 PushEventHandler(inputHandler
);
732 m_extraEvtHandler
= inputHandler
;
735 void wxComboCtrlBase::CreateTextCtrl( int extraStyle
, const wxValidator
& validator
)
737 if ( !(m_windowStyle
& wxCB_READONLY
) )
739 m_text
= new wxTextCtrl(this,
744 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
745 // not used by the wxPropertyGrid and therefore the tab is
746 // processed by looking at ancestors to see if they have
747 // wxTAB_TRAVERSAL. The navigation event is then sent to
754 // This is required for some platforms (GTK+ atleast)
755 m_text
->SetSizeHints(2,4);
759 void wxComboCtrlBase::OnThemeChange()
761 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
764 wxComboCtrlBase::~wxComboCtrlBase()
769 delete gs_doubleBuffer
;
770 gs_doubleBuffer
= (wxBitmap
*) NULL
;
772 #if INSTALL_TOPLEV_HANDLER
773 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
774 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
779 RemoveEventHandler(m_extraEvtHandler
);
782 m_text
->RemoveEventHandler(m_textEvtHandler
);
784 delete m_textEvtHandler
;
785 delete m_extraEvtHandler
;
789 // ----------------------------------------------------------------------------
791 // ----------------------------------------------------------------------------
793 // Recalculates button and textctrl areas
794 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
796 wxSize sz
= GetClientSize();
797 int customBorder
= m_widthCustomBorder
;
798 int btnBorder
; // border for button only
800 // check if button should really be outside the border: we'll do it it if
801 // its platform default or bitmap+pushbutton background is used, but not if
802 // there is vertical size adjustment or horizontal spacing.
803 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
804 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
805 m_btnSpacingX
== 0 &&
808 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
813 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
814 btnBorder
= customBorder
;
817 // Defaul indentation
818 if ( m_absIndent
< 0 )
819 m_absIndent
= GetNativeTextIndent();
821 int butWidth
= btnWidth
;
824 butWidth
= m_btnWidDefault
;
826 m_btnWidDefault
= butWidth
;
831 // Adjust button width
833 butWidth
+= m_btnWid
;
834 else if ( m_btnWid
> 0 )
837 int butHeight
= sz
.y
;
839 butHeight
-= btnBorder
*2;
841 // Adjust button height
843 butHeight
+= m_btnHei
;
844 else if ( m_btnHei
> 0 )
845 butHeight
= m_btnHei
;
847 // Use size of normal bitmap if...
850 // button width is set to default and blank button bg is not drawn
851 if ( m_bmpNormal
.Ok() )
853 int bmpReqWidth
= m_bmpNormal
.GetWidth();
854 int bmpReqHeight
= m_bmpNormal
.GetHeight();
856 // If drawing blank button background, we need to add some margin.
857 if ( m_blankButtonBg
)
859 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
860 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
863 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
864 butWidth
= bmpReqWidth
;
865 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
866 butHeight
= bmpReqHeight
;
868 // Need to fix height?
869 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
871 int newY
= butHeight
+(customBorder
*2);
872 SetClientSize(-1,newY
);
877 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
879 m_btnSize
.x
= butWidth
;
880 m_btnSize
.y
= butHeight
;
882 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
883 m_btnArea
.y
= btnBorder
;
884 m_btnArea
.width
= butAreaWid
;
885 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
887 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
888 m_tcArea
.y
= customBorder
;
889 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
890 m_tcArea
.height
= sz
.y
- (customBorder
*2);
895 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
896 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
901 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
906 wxSize sz
= GetClientSize();
907 int customBorder
= m_widthCustomBorder
;
909 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
912 int tcSizeY
= m_text
->GetBestSize().y
;
913 int diff
= sz
.y
- tcSizeY
;
914 int y
= textCtrlYAdjust
+ (diff
/2);
916 if ( y
< customBorder
)
919 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
921 m_tcArea
.width
- COMBO_MARGIN
-
922 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
925 // Make sure textctrl doesn't exceed the bottom custom border
926 wxSize tsz
= m_text
->GetSize();
927 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
930 tsz
.y
= tsz
.y
- diff
- 1;
931 m_text
->SetSize(tsz
);
936 m_text
->SetSize( m_tcArea
.x
,
938 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
943 wxSize
wxComboCtrlBase::DoGetBestSize() const
945 wxSize
sizeText(150,0);
948 sizeText
= m_text
->GetBestSize();
950 // TODO: Better method to calculate close-to-native control height.
954 fhei
= (m_font
.GetPointSize()*2) + 5;
955 else if ( wxNORMAL_FONT
->Ok() )
956 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
958 fhei
= sizeText
.y
+ 4;
960 // Need to force height to accomodate bitmap?
961 int btnSizeY
= m_btnSize
.y
;
962 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
965 // Control height doesn't depend on border
968 int border = m_windowStyle & wxBORDER_MASK;
969 if ( border == wxSIMPLE_BORDER )
971 else if ( border == wxNO_BORDER )
972 fhei += (m_widthCustomBorder*2);
983 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
990 void wxComboCtrlBase::DoMoveWindow(int x
, int y
, int width
, int height
)
992 // SetSize is called last in create, so it marks the end of creation
993 m_iFlags
|= wxCC_IFLAG_CREATED
;
995 wxControl::DoMoveWindow(x
, y
, width
, height
);
998 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1003 // defined by actual wxComboCtrls
1009 // ----------------------------------------------------------------------------
1010 // standard operations
1011 // ----------------------------------------------------------------------------
1013 bool wxComboCtrlBase::Enable(bool enable
)
1015 if ( !wxControl::Enable(enable
) )
1019 m_btn
->Enable(enable
);
1021 m_text
->Enable(enable
);
1026 bool wxComboCtrlBase::Show(bool show
)
1028 if ( !wxControl::Show(show
) )
1040 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1042 if ( !wxControl::SetFont(font
) )
1046 m_text
->SetFont(font
);
1052 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1054 wxControl::DoSetToolTip(tooltip
);
1056 // Set tool tip for button and text box
1059 const wxString
&tip
= tooltip
->GetTip();
1060 if ( m_text
) m_text
->SetToolTip(tip
);
1061 if ( m_btn
) m_btn
->SetToolTip(tip
);
1065 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1066 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1069 #endif // wxUSE_TOOLTIPS
1071 // ----------------------------------------------------------------------------
1073 // ----------------------------------------------------------------------------
1075 // draw focus background on area in a way typical on platform
1076 void wxComboCtrlBase::DrawFocusBackground( wxDC
& dc
, const wxRect
& rect
, int flags
)
1078 wxSize sz
= GetClientSize();
1080 bool isFocused
; // also selected
1082 // For smaller size control (and for disabled background) use less spacing
1086 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1089 isEnabled
= IsEnabled();
1090 isFocused
= ShouldDrawFocus();
1092 // Windows-style: for smaller size control (and for disabled background) use less spacing
1093 focusSpacingX
= isEnabled
? 2 : 1;
1094 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1098 // Drawing a list item
1099 isEnabled
= true; // they are never disabled
1100 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1106 // Set the background sub-rectangle for selection, disabled etc
1107 wxRect
selRect(rect
);
1108 selRect
.y
+= focusSpacingY
;
1109 selRect
.height
-= (focusSpacingY
*2);
1110 selRect
.x
+= m_widthCustomPaint
+ focusSpacingX
;
1111 selRect
.width
-= m_widthCustomPaint
+ (focusSpacingX
*2);
1117 // If popup is hidden and this control is focused,
1118 // then draw the focus-indicator (selbgcolor background etc.).
1121 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1122 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1126 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1127 bgCol
= GetBackgroundColour();
1132 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1133 bgCol
= GetBackgroundColour();
1136 dc
.SetBrush( bgCol
);
1138 dc
.DrawRectangle( selRect
);
1141 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1143 int drawState
= m_btnState
;
1146 if ( m_isPopupShown
)
1147 drawState
|= wxCONTROL_PRESSED
;
1150 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1151 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1155 // Make sure area is not larger than the control
1156 if ( drawRect
.y
< rect
.y
)
1157 drawRect
.y
= rect
.y
;
1158 if ( drawRect
.height
> rect
.height
)
1159 drawRect
.height
= rect
.height
;
1161 bool enabled
= IsEnabled();
1164 drawState
|= wxCONTROL_DISABLED
;
1166 if ( !m_bmpNormal
.Ok() )
1168 // Need to clear button background even if m_btn is present
1173 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1174 bgCol
= GetParent()->GetBackgroundColour();
1176 bgCol
= GetBackgroundColour();
1180 dc
.DrawRectangle(rect
);
1183 // Draw standard button
1184 wxRendererNative::Get().DrawComboBoxDropButton(this,
1196 pBmp
= &m_bmpDisabled
;
1197 else if ( m_btnState
& wxCONTROL_PRESSED
)
1198 pBmp
= &m_bmpPressed
;
1199 else if ( m_btnState
& wxCONTROL_CURRENT
)
1202 pBmp
= &m_bmpNormal
;
1204 if ( m_blankButtonBg
)
1206 // If using blank button background, we need to clear its background
1207 // with button face colour instead of colour for rest of the control.
1210 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1211 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1214 dc
.DrawRectangle(rect
);
1217 wxRendererNative::Get().DrawPushButton(this,
1226 // Need to clear button background even if m_btn is present
1227 // (assume non-button background was cleared just before this call so brushes are good)
1229 dc
.DrawRectangle(rect
);
1232 // Draw bitmap centered in drawRect
1233 dc
.DrawBitmap(*pBmp
,
1234 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1235 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1240 void wxComboCtrlBase::RecalcAndRefresh()
1244 wxSizeEvent
evt(GetSize(),GetId());
1245 GetEventHandler()->ProcessEvent(evt
);
1250 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1252 // If size is larger, recalculate double buffer bitmap
1253 if ( !gs_doubleBuffer
||
1254 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1255 sz
.y
> gs_doubleBuffer
->GetHeight() )
1257 delete gs_doubleBuffer
;
1258 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1260 return *gs_doubleBuffer
;
1263 // ----------------------------------------------------------------------------
1264 // miscellaneous event handlers
1265 // ----------------------------------------------------------------------------
1267 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1269 // Change event id and relay it forward
1270 event
.SetId(GetId());
1274 // call if cursor is on button area or mouse is captured for the button
1275 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1278 int type
= event
.GetEventType();
1280 if ( type
== wxEVT_MOTION
)
1282 if ( flags
& wxCC_MF_ON_BUTTON
)
1284 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1286 // Mouse hover begins
1287 m_btnState
|= wxCONTROL_CURRENT
;
1288 if ( HasCapture() ) // Retain pressed state.
1289 m_btnState
|= wxCONTROL_PRESSED
;
1293 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1296 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1300 else if ( type
== wxEVT_LEFT_DOWN
)
1302 // Only accept event if it wasn't right after popup dismiss
1303 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1305 // Need to test this, because it might be outside.
1306 if ( flags
& wxCC_MF_ON_BUTTON
)
1308 m_btnState
|= wxCONTROL_PRESSED
;
1311 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1314 // If showing popup now, do not capture mouse or there will be interference
1323 else if ( type
== wxEVT_LEFT_UP
)
1326 // Only accept event if mouse was left-press was previously accepted
1330 if ( m_btnState
& wxCONTROL_PRESSED
)
1332 // If mouse was inside, fire the click event.
1333 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1335 if ( flags
& wxCC_MF_ON_BUTTON
)
1339 m_btnState
&= ~(wxCONTROL_PRESSED
);
1343 else if ( type
== wxEVT_LEAVE_WINDOW
)
1345 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1347 m_btnState
&= ~(wxCONTROL_CURRENT
);
1350 if ( !m_isPopupShown
)
1352 m_btnState
&= ~(wxCONTROL_PRESSED
);
1363 // Conversion to double-clicks and some basic filtering
1364 // returns true if event was consumed or filtered
1365 //bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
1366 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1369 wxLongLong t
= ::wxGetLocalTimeMillis();
1370 int evtType
= event
.GetEventType();
1373 // Generate our own double-clicks
1374 // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
1375 if ( (m_windowStyle
& wxCC_SPECIAL_DCLICK
) &&
1377 //!(handlerFlags & wxCC_MF_ON_BUTTON) )
1378 !(flags
& wxCC_MF_ON_BUTTON
) )
1380 if ( evtType
== wxEVT_LEFT_DOWN
)
1382 // Set value to avoid up-events without corresponding downs
1383 m_downReceived
= true;
1385 else if ( evtType
== wxEVT_LEFT_DCLICK
)
1387 // We'll make our own double-clicks
1389 event
.SetEventType(0);
1392 else if ( evtType
== wxEVT_LEFT_UP
)
1394 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
1396 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
1398 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
1400 //type = wxEVT_LEFT_DCLICK;
1401 event
.SetEventType(wxEVT_LEFT_DCLICK
);
1402 m_timeLastMouseUp
= 1;
1406 m_timeLastMouseUp
= t
;
1409 //m_downReceived = false;
1414 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1415 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1417 event
.SetEventType(0);
1424 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1426 int evtType
= event
.GetEventType();
1428 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1429 (m_windowStyle
& wxCB_READONLY
) )
1431 if ( m_isPopupShown
)
1434 // Normally do nothing - evt handler should close it for us
1435 #elif !USE_TRANSIENT_POPUP
1436 // Click here always hides the popup.
1442 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1444 // In read-only mode, clicking the text is the
1445 // same as clicking the button.
1448 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1450 //if ( m_popupInterface->CycleValue() )
1452 if ( m_popupInterface
)
1453 m_popupInterface
->OnComboDoubleClick();
1458 if ( m_isPopupShown
)
1460 // relay (some) mouse events to the popup
1461 if ( evtType
== wxEVT_MOUSEWHEEL
)
1462 m_popup
->AddPendingEvent(event
);
1468 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& )
1470 // First click is the first part of double-click
1471 // Some platforms don't generate down-less mouse up-event
1472 // (Windows does, GTK+2 doesn't), so that's why we have
1474 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
1481 // no need to check for m_widthCustomPaint - that
1482 // area never gets special handling when selected
1483 // (in writable mode, that is)
1487 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1490 // indentation may also have changed
1491 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1492 m_absIndent
= GetNativeTextIndent();
1496 // ----------------------------------------------------------------------------
1498 // ----------------------------------------------------------------------------
1500 // Create popup window and the child control
1501 void wxComboCtrlBase::CreatePopup()
1503 wxComboPopup
* popupInterface
= m_popupInterface
;
1507 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1509 popupInterface
->Create(m_winPopup
);
1510 m_popup
= popup
= popupInterface
->GetControl();
1512 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1513 popup
->PushEventHandler( m_popupExtraHandler
);
1515 // This may be helpful on some platforms
1516 // (eg. it bypasses a wxGTK popupwindow bug where
1517 // window is not initially hidden when it should be)
1520 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1523 // Destroy popup window and the child control
1524 void wxComboCtrlBase::DestroyPopup()
1527 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1529 delete m_popupExtraHandler
;
1533 delete m_popupInterface
;
1536 m_winPopup
->Destroy();
1538 m_popupInterface
= (wxComboPopup
*) NULL
;
1539 m_winPopup
= (wxWindow
*) NULL
;
1540 m_popup
= (wxWindow
*) NULL
;
1543 void wxComboCtrlBase::SetPopupControl( wxComboPopup
* iface
)
1545 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1549 iface
->InitBase(this);
1552 m_popupInterface
= iface
;
1554 if ( !iface
->LazyCreate() )
1560 m_popup
= (wxWindow
*) NULL
;
1563 // This must be done after creation
1564 if ( m_valueString
.length() )
1566 iface
->SetStringValue(m_valueString
);
1571 // Ensures there is atleast the default popup
1572 void wxComboCtrlBase::EnsurePopupControl()
1574 if ( !m_popupInterface
)
1575 SetPopupControl(NULL
);
1578 void wxComboCtrlBase::OnButtonClick()
1580 // Derived classes can override this method for totally custom
1585 void wxComboCtrlBase::ShowPopup()
1587 EnsurePopupControl();
1588 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1592 // Space above and below
1598 wxSize ctrlSz
= GetSize();
1600 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1601 scrPos
= GetParent()->ClientToScreen(GetPosition());
1603 spaceAbove
= scrPos
.y
;
1604 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1606 maxHeightPopup
= spaceBelow
;
1607 if ( spaceAbove
> spaceBelow
)
1608 maxHeightPopup
= spaceAbove
;
1611 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1613 if ( widthPopup
< m_widthMinPopup
)
1614 widthPopup
= m_widthMinPopup
;
1616 wxWindow
* winPopup
= m_winPopup
;
1619 // Need to disable tab traversal of parent
1621 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1622 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1623 // that if transient popup is open, then tab traversal is to be ignored.
1624 // However, I think this code would still be needed for cases where
1625 // transient popup doesn't work yet (wxWinCE?).
1626 wxWindow
* parent
= GetParent();
1627 int parentFlags
= parent
->GetWindowStyle();
1628 if ( parentFlags
& wxTAB_TRAVERSAL
)
1630 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1631 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1637 winPopup
= m_winPopup
;
1645 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1647 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1648 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1651 popup
->SetSize(adjustedSize
);
1653 m_popupInterface
->OnPopup();
1656 // Reposition and resize popup window
1659 wxSize szp
= popup
->GetSize();
1662 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1664 // Default anchor is wxLEFT
1665 int anchorSide
= m_anchorSide
;
1667 anchorSide
= wxLEFT
;
1669 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1670 int leftX
= scrPos
.x
- m_extLeft
;
1671 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1673 // If there is not enough horizontal space, anchor on the other side.
1674 // If there is no space even then, place the popup at x 0.
1675 if ( anchorSide
== wxRIGHT
)
1679 if ( (leftX
+szp
.x
) < screenWidth
)
1680 anchorSide
= wxLEFT
;
1687 if ( (leftX
+szp
.x
) >= screenWidth
)
1690 anchorSide
= wxRIGHT
;
1696 // Select x coordinate according to the anchor side
1697 if ( anchorSide
== wxRIGHT
)
1699 else if ( anchorSide
== wxLEFT
)
1704 if ( spaceBelow
< szp
.y
)
1706 popupY
= scrPos
.y
- szp
.y
;
1710 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1711 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1713 // Some platforms (GTK) may need these two to be separate
1714 winPopup
->SetSize( szp
.x
, szp
.y
);
1715 winPopup
->Move( popupX
, popupY
);
1717 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1721 // Set string selection (must be this way instead of SetStringSelection)
1724 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1725 m_text
->SelectAll();
1727 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1731 // This is neede since focus/selection indication may change when popup is shown
1735 // This must be after SetStringValue
1736 m_isPopupShown
= true;
1739 #if USE_TRANSIENT_POPUP
1740 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1745 #if INSTALL_TOPLEV_HANDLER
1746 // Put top level window event handler into place
1747 if ( !m_toplevEvtHandler
)
1748 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1750 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1752 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1753 toplev
->PushEventHandler( m_toplevEvtHandler
);
1758 void wxComboCtrlBase::OnPopupDismiss()
1760 // Just in case, avoid double dismiss
1761 if ( !m_isPopupShown
)
1764 // *Must* set this before focus etc.
1765 m_isPopupShown
= false;
1767 // Inform popup control itself
1768 m_popupInterface
->OnDismiss();
1770 if ( m_popupExtraHandler
)
1771 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1773 #if INSTALL_TOPLEV_HANDLER
1774 // Remove top level window event handler
1775 if ( m_toplevEvtHandler
)
1777 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1779 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1783 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1785 // If cursor not on dropdown button, then clear its state
1786 // (technically not required by all ports, but do it for all just in case)
1787 if ( !m_btnArea
.Inside(ScreenToClient(::wxGetMousePosition())) )
1790 // Return parent's tab traversal flag.
1791 // See ShowPopup for notes.
1792 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1794 wxWindow
* parent
= GetParent();
1795 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1796 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1799 // refresh control (necessary even if m_text)
1808 void wxComboCtrlBase::HidePopup()
1810 // Should be able to call this without popup interface
1811 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1812 if ( !m_isPopupShown
)
1815 // transfer value and show it in textctrl, if any
1816 SetValue( m_popupInterface
->GetStringValue() );
1818 #if USE_TRANSIENT_POPUP
1819 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1827 // ----------------------------------------------------------------------------
1828 // customization methods
1829 // ----------------------------------------------------------------------------
1831 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1832 int side
, int spacingX
)
1837 m_btnSpacingX
= spacingX
;
1842 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1844 const wxBitmap
& bmpPressed
,
1845 const wxBitmap
& bmpHover
,
1846 const wxBitmap
& bmpDisabled
)
1848 m_bmpNormal
= bmpNormal
;
1849 m_blankButtonBg
= blankButtonBg
;
1851 if ( bmpPressed
.Ok() )
1852 m_bmpPressed
= bmpPressed
;
1854 m_bmpPressed
= bmpNormal
;
1856 if ( bmpHover
.Ok() )
1857 m_bmpHover
= bmpHover
;
1859 m_bmpHover
= bmpNormal
;
1861 if ( bmpDisabled
.Ok() )
1862 m_bmpDisabled
= bmpDisabled
;
1864 m_bmpDisabled
= bmpNormal
;
1869 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1873 // move textctrl accordingly
1874 wxRect r
= m_text
->GetRect();
1875 int inc
= width
- m_widthCustomPaint
;
1878 m_text
->SetSize( r
);
1881 m_widthCustomPaint
= width
;
1886 void wxComboCtrlBase::SetTextIndent( int indent
)
1890 m_absIndent
= GetNativeTextIndent();
1891 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1895 m_absIndent
= indent
;
1896 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1902 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1904 return DEFAULT_TEXT_INDENT
;
1907 // ----------------------------------------------------------------------------
1908 // methods forwarded to wxTextCtrl
1909 // ----------------------------------------------------------------------------
1911 wxString
wxComboCtrlBase::GetValue() const
1914 return m_text
->GetValue();
1915 return m_valueString
;
1918 void wxComboCtrlBase::SetValue(const wxString
& value
)
1922 m_text
->SetValue(value
);
1923 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1924 m_text
->SelectAll();
1927 m_valueString
= value
;
1931 // Since wxComboPopup may want to paint the combo as well, we need
1932 // to set the string value here (as well as sometimes in ShowPopup).
1933 if ( m_valueString
!= value
&& m_popupInterface
)
1935 m_popupInterface
->SetStringValue(value
);
1939 // In this SetValue variant wxComboPopup::SetStringValue is not called
1940 void wxComboCtrlBase::SetText(const wxString
& value
)
1942 // Unlike in SetValue(), this must be called here or
1943 // the behaviour will no be consistent in readonlys.
1944 EnsurePopupControl();
1946 m_valueString
= value
;
1951 void wxComboCtrlBase::Copy()
1957 void wxComboCtrlBase::Cut()
1963 void wxComboCtrlBase::Paste()
1969 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1972 m_text
->SetInsertionPoint(pos
);
1975 void wxComboCtrlBase::SetInsertionPointEnd()
1978 m_text
->SetInsertionPointEnd();
1981 long wxComboCtrlBase::GetInsertionPoint() const
1984 return m_text
->GetInsertionPoint();
1989 long wxComboCtrlBase::GetLastPosition() const
1992 return m_text
->GetLastPosition();
1997 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2000 m_text
->Replace(from
, to
, value
);
2003 void wxComboCtrlBase::Remove(long from
, long to
)
2006 m_text
->Remove(from
, to
);
2009 void wxComboCtrlBase::SetSelection(long from
, long to
)
2012 m_text
->SetSelection(from
, to
);
2015 void wxComboCtrlBase::Undo()
2021 #endif // wxUSE_COMBOCTRL