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
;
799 int btnBorder
; // border for button only
801 // check if button should really be outside the border: we'll do it it if
802 // its platform default or bitmap+pushbutton background is used, but not if
803 // there is vertical size adjustment or horizontal spacing.
804 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
805 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
806 m_btnSpacingX
== 0 &&
809 buttonOutside
= true;
810 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
815 buttonOutside
= false;
816 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
817 btnBorder
= customBorder
;
820 // Defaul indentation
821 if ( m_absIndent
< 0 )
822 m_absIndent
= GetNativeTextIndent();
824 int butWidth
= btnWidth
;
827 butWidth
= m_btnWidDefault
;
829 m_btnWidDefault
= butWidth
;
834 // Adjust button width
836 butWidth
+= m_btnWid
;
837 else if ( m_btnWid
> 0 )
840 int butHeight
= sz
.y
;
842 butHeight
-= btnBorder
*2;
844 // Adjust button height
846 butHeight
+= m_btnHei
;
847 else if ( m_btnHei
> 0 )
848 butHeight
= m_btnHei
;
850 // Use size of normal bitmap if...
853 // button width is set to default and blank button bg is not drawn
854 if ( m_bmpNormal
.Ok() )
856 int bmpReqWidth
= m_bmpNormal
.GetWidth();
857 int bmpReqHeight
= m_bmpNormal
.GetHeight();
859 // If drawing blank button background, we need to add some margin.
860 if ( m_blankButtonBg
)
862 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
863 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
866 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
867 butWidth
= bmpReqWidth
;
868 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
869 butHeight
= bmpReqHeight
;
871 // Need to fix height?
872 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
874 int newY
= butHeight
+(customBorder
*2);
875 SetClientSize(-1,newY
);
880 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
882 m_btnSize
.x
= butWidth
;
883 m_btnSize
.y
= butHeight
;
885 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
886 m_btnArea
.y
= btnBorder
;
887 m_btnArea
.width
= butAreaWid
;
888 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
890 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
891 m_tcArea
.y
= customBorder
;
892 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
893 m_tcArea
.height
= sz
.y
- (customBorder
*2);
898 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
899 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
904 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
909 wxSize sz
= GetClientSize();
910 int customBorder
= m_widthCustomBorder
;
912 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
915 int tcSizeY
= m_text
->GetBestSize().y
;
916 int diff
= sz
.y
- tcSizeY
;
917 int y
= textCtrlYAdjust
+ (diff
/2);
919 if ( y
< customBorder
)
922 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
924 m_tcArea
.width
- COMBO_MARGIN
-
925 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
928 // Make sure textctrl doesn't exceed the bottom custom border
929 wxSize tsz
= m_text
->GetSize();
930 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
933 tsz
.y
= tsz
.y
- diff
- 1;
934 m_text
->SetSize(tsz
);
939 m_text
->SetSize( m_tcArea
.x
,
941 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
946 wxSize
wxComboCtrlBase::DoGetBestSize() const
948 wxSize
sizeText(150,0);
951 sizeText
= m_text
->GetBestSize();
953 // TODO: Better method to calculate close-to-native control height.
957 fhei
= (m_font
.GetPointSize()*2) + 5;
958 else if ( wxNORMAL_FONT
->Ok() )
959 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
961 fhei
= sizeText
.y
+ 4;
963 // Need to force height to accomodate bitmap?
964 int btnSizeY
= m_btnSize
.y
;
965 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
968 // Control height doesn't depend on border
971 int border = m_windowStyle & wxBORDER_MASK;
972 if ( border == wxSIMPLE_BORDER )
974 else if ( border == wxNO_BORDER )
975 fhei += (m_widthCustomBorder*2);
986 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
993 void wxComboCtrlBase::DoMoveWindow(int x
, int y
, int width
, int height
)
995 // SetSize is called last in create, so it marks the end of creation
996 m_iFlags
|= wxCC_IFLAG_CREATED
;
998 wxControl::DoMoveWindow(x
, y
, width
, height
);
1001 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1006 // defined by actual wxComboCtrls
1012 // ----------------------------------------------------------------------------
1013 // standard operations
1014 // ----------------------------------------------------------------------------
1016 bool wxComboCtrlBase::Enable(bool enable
)
1018 if ( !wxControl::Enable(enable
) )
1022 m_btn
->Enable(enable
);
1024 m_text
->Enable(enable
);
1029 bool wxComboCtrlBase::Show(bool show
)
1031 if ( !wxControl::Show(show
) )
1043 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1045 if ( !wxControl::SetFont(font
) )
1049 m_text
->SetFont(font
);
1055 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1057 wxControl::DoSetToolTip(tooltip
);
1059 // Set tool tip for button and text box
1062 const wxString
&tip
= tooltip
->GetTip();
1063 if ( m_text
) m_text
->SetToolTip(tip
);
1064 if ( m_btn
) m_btn
->SetToolTip(tip
);
1068 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1069 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1072 #endif // wxUSE_TOOLTIPS
1074 // ----------------------------------------------------------------------------
1076 // ----------------------------------------------------------------------------
1078 // draw focus background on area in a way typical on platform
1079 void wxComboCtrlBase::DrawFocusBackground( wxDC
& dc
, const wxRect
& rect
, int flags
)
1081 wxSize sz
= GetClientSize();
1083 bool isFocused
; // also selected
1085 // For smaller size control (and for disabled background) use less spacing
1089 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1092 isEnabled
= IsEnabled();
1093 isFocused
= ShouldDrawFocus();
1095 // Windows-style: for smaller size control (and for disabled background) use less spacing
1096 focusSpacingX
= isEnabled
? 2 : 1;
1097 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1101 // Drawing a list item
1102 isEnabled
= true; // they are never disabled
1103 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1109 // Set the background sub-rectangle for selection, disabled etc
1110 wxRect
selRect(rect
);
1111 selRect
.y
+= focusSpacingY
;
1112 selRect
.height
-= (focusSpacingY
*2);
1113 selRect
.x
+= m_widthCustomPaint
+ focusSpacingX
;
1114 selRect
.width
-= m_widthCustomPaint
+ (focusSpacingX
*2);
1120 // If popup is hidden and this control is focused,
1121 // then draw the focus-indicator (selbgcolor background etc.).
1124 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1125 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1129 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1130 bgCol
= GetBackgroundColour();
1135 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1136 bgCol
= GetBackgroundColour();
1139 dc
.SetBrush( bgCol
);
1141 dc
.DrawRectangle( selRect
);
1144 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1146 int drawState
= m_btnState
;
1149 if ( m_isPopupShown
)
1150 drawState
|= wxCONTROL_PRESSED
;
1153 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1154 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1158 // Make sure area is not larger than the control
1159 if ( drawRect
.y
< rect
.y
)
1160 drawRect
.y
= rect
.y
;
1161 if ( drawRect
.height
> rect
.height
)
1162 drawRect
.height
= rect
.height
;
1164 bool enabled
= IsEnabled();
1167 drawState
|= wxCONTROL_DISABLED
;
1169 if ( !m_bmpNormal
.Ok() )
1171 // Need to clear button background even if m_btn is present
1176 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1177 bgCol
= GetParent()->GetBackgroundColour();
1179 bgCol
= GetBackgroundColour();
1183 dc
.DrawRectangle(rect
);
1186 // Draw standard button
1187 wxRendererNative::Get().DrawComboBoxDropButton(this,
1199 pBmp
= &m_bmpDisabled
;
1200 else if ( m_btnState
& wxCONTROL_PRESSED
)
1201 pBmp
= &m_bmpPressed
;
1202 else if ( m_btnState
& wxCONTROL_CURRENT
)
1205 pBmp
= &m_bmpNormal
;
1207 if ( m_blankButtonBg
)
1209 // If using blank button background, we need to clear its background
1210 // with button face colour instead of colour for rest of the control.
1213 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1214 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1217 dc
.DrawRectangle(rect
);
1220 wxRendererNative::Get().DrawPushButton(this,
1229 // Need to clear button background even if m_btn is present
1230 // (assume non-button background was cleared just before this call so brushes are good)
1232 dc
.DrawRectangle(rect
);
1235 // Draw bitmap centered in drawRect
1236 dc
.DrawBitmap(*pBmp
,
1237 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1238 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1243 void wxComboCtrlBase::RecalcAndRefresh()
1247 wxSizeEvent
evt(GetSize(),GetId());
1248 GetEventHandler()->ProcessEvent(evt
);
1253 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1255 // If size is larger, recalculate double buffer bitmap
1256 if ( !gs_doubleBuffer
||
1257 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1258 sz
.y
> gs_doubleBuffer
->GetHeight() )
1260 delete gs_doubleBuffer
;
1261 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1263 return *gs_doubleBuffer
;
1266 // ----------------------------------------------------------------------------
1267 // miscellaneous event handlers
1268 // ----------------------------------------------------------------------------
1270 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1272 // Change event id and relay it forward
1273 event
.SetId(GetId());
1277 // call if cursor is on button area or mouse is captured for the button
1278 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1281 int type
= event
.GetEventType();
1283 if ( type
== wxEVT_MOTION
)
1285 if ( flags
& wxCC_MF_ON_BUTTON
)
1287 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1289 // Mouse hover begins
1290 m_btnState
|= wxCONTROL_CURRENT
;
1291 if ( HasCapture() ) // Retain pressed state.
1292 m_btnState
|= wxCONTROL_PRESSED
;
1296 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1299 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1303 else if ( type
== wxEVT_LEFT_DOWN
)
1305 // Only accept event if it wasn't right after popup dismiss
1306 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1308 // Need to test this, because it might be outside.
1309 if ( flags
& wxCC_MF_ON_BUTTON
)
1311 m_btnState
|= wxCONTROL_PRESSED
;
1314 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1317 // If showing popup now, do not capture mouse or there will be interference
1326 else if ( type
== wxEVT_LEFT_UP
)
1329 // Only accept event if mouse was left-press was previously accepted
1333 if ( m_btnState
& wxCONTROL_PRESSED
)
1335 // If mouse was inside, fire the click event.
1336 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1338 if ( flags
& wxCC_MF_ON_BUTTON
)
1342 m_btnState
&= ~(wxCONTROL_PRESSED
);
1346 else if ( type
== wxEVT_LEAVE_WINDOW
)
1348 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1350 m_btnState
&= ~(wxCONTROL_CURRENT
);
1353 if ( !m_isPopupShown
)
1355 m_btnState
&= ~(wxCONTROL_PRESSED
);
1366 // Conversion to double-clicks and some basic filtering
1367 // returns true if event was consumed or filtered
1368 //bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
1369 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1372 wxLongLong t
= ::wxGetLocalTimeMillis();
1373 int evtType
= event
.GetEventType();
1376 // Generate our own double-clicks
1377 // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
1378 if ( (m_windowStyle
& wxCC_SPECIAL_DCLICK
) &&
1380 //!(handlerFlags & wxCC_MF_ON_BUTTON) )
1381 !(flags
& wxCC_MF_ON_BUTTON
) )
1383 if ( evtType
== wxEVT_LEFT_DOWN
)
1385 // Set value to avoid up-events without corresponding downs
1386 m_downReceived
= true;
1388 else if ( evtType
== wxEVT_LEFT_DCLICK
)
1390 // We'll make our own double-clicks
1392 event
.SetEventType(0);
1395 else if ( evtType
== wxEVT_LEFT_UP
)
1397 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
1399 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
1401 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
1403 //type = wxEVT_LEFT_DCLICK;
1404 event
.SetEventType(wxEVT_LEFT_DCLICK
);
1405 m_timeLastMouseUp
= 1;
1409 m_timeLastMouseUp
= t
;
1412 //m_downReceived = false;
1417 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1418 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1420 event
.SetEventType(0);
1427 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1429 int evtType
= event
.GetEventType();
1431 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1432 (m_windowStyle
& wxCB_READONLY
) )
1434 if ( m_isPopupShown
)
1437 // Normally do nothing - evt handler should close it for us
1438 #elif !USE_TRANSIENT_POPUP
1439 // Click here always hides the popup.
1445 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1447 // In read-only mode, clicking the text is the
1448 // same as clicking the button.
1451 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1453 //if ( m_popupInterface->CycleValue() )
1455 if ( m_popupInterface
)
1456 m_popupInterface
->OnComboDoubleClick();
1461 if ( m_isPopupShown
)
1463 // relay (some) mouse events to the popup
1464 if ( evtType
== wxEVT_MOUSEWHEEL
)
1465 m_popup
->AddPendingEvent(event
);
1471 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& )
1473 // First click is the first part of double-click
1474 // Some platforms don't generate down-less mouse up-event
1475 // (Windows does, GTK+2 doesn't), so that's why we have
1477 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
1484 // no need to check for m_widthCustomPaint - that
1485 // area never gets special handling when selected
1486 // (in writable mode, that is)
1490 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1493 // indentation may also have changed
1494 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1495 m_absIndent
= GetNativeTextIndent();
1499 // ----------------------------------------------------------------------------
1501 // ----------------------------------------------------------------------------
1503 // Create popup window and the child control
1504 void wxComboCtrlBase::CreatePopup()
1506 wxComboPopup
* popupInterface
= m_popupInterface
;
1510 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1512 popupInterface
->Create(m_winPopup
);
1513 m_popup
= popup
= popupInterface
->GetControl();
1515 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1516 popup
->PushEventHandler( m_popupExtraHandler
);
1518 // This may be helpful on some platforms
1519 // (eg. it bypasses a wxGTK popupwindow bug where
1520 // window is not initially hidden when it should be)
1523 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1526 // Destroy popup window and the child control
1527 void wxComboCtrlBase::DestroyPopup()
1530 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1532 delete m_popupExtraHandler
;
1536 delete m_popupInterface
;
1539 m_winPopup
->Destroy();
1541 m_popupInterface
= (wxComboPopup
*) NULL
;
1542 m_winPopup
= (wxWindow
*) NULL
;
1543 m_popup
= (wxWindow
*) NULL
;
1546 void wxComboCtrlBase::SetPopupControl( wxComboPopup
* iface
)
1548 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1552 iface
->InitBase(this);
1555 m_popupInterface
= iface
;
1557 if ( !iface
->LazyCreate() )
1563 m_popup
= (wxWindow
*) NULL
;
1566 // This must be done after creation
1567 if ( m_valueString
.length() )
1569 iface
->SetStringValue(m_valueString
);
1574 // Ensures there is atleast the default popup
1575 void wxComboCtrlBase::EnsurePopupControl()
1577 if ( !m_popupInterface
)
1578 SetPopupControl(NULL
);
1581 void wxComboCtrlBase::OnButtonClick()
1583 // Derived classes can override this method for totally custom
1588 void wxComboCtrlBase::ShowPopup()
1590 EnsurePopupControl();
1591 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1595 // Space above and below
1601 wxSize ctrlSz
= GetSize();
1603 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1604 scrPos
= GetParent()->ClientToScreen(GetPosition());
1606 spaceAbove
= scrPos
.y
;
1607 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1609 maxHeightPopup
= spaceBelow
;
1610 if ( spaceAbove
> spaceBelow
)
1611 maxHeightPopup
= spaceAbove
;
1614 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1616 if ( widthPopup
< m_widthMinPopup
)
1617 widthPopup
= m_widthMinPopup
;
1619 wxWindow
* winPopup
= m_winPopup
;
1622 // Need to disable tab traversal of parent
1624 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1625 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1626 // that if transient popup is open, then tab traversal is to be ignored.
1627 // However, I think this code would still be needed for cases where
1628 // transient popup doesn't work yet (wxWinCE?).
1629 wxWindow
* parent
= GetParent();
1630 int parentFlags
= parent
->GetWindowStyle();
1631 if ( parentFlags
& wxTAB_TRAVERSAL
)
1633 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1634 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1640 winPopup
= m_winPopup
;
1648 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1650 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1651 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1654 popup
->SetSize(adjustedSize
);
1656 m_popupInterface
->OnPopup();
1659 // Reposition and resize popup window
1662 wxSize szp
= popup
->GetSize();
1665 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1667 // Default anchor is wxLEFT
1668 int anchorSide
= m_anchorSide
;
1670 anchorSide
= wxLEFT
;
1672 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1673 int leftX
= scrPos
.x
- m_extLeft
;
1674 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1676 // If there is not enough horizontal space, anchor on the other side.
1677 // If there is no space even then, place the popup at x 0.
1678 if ( anchorSide
== wxRIGHT
)
1682 if ( (leftX
+szp
.x
) < screenWidth
)
1683 anchorSide
= wxLEFT
;
1690 if ( (leftX
+szp
.x
) >= screenWidth
)
1693 anchorSide
= wxRIGHT
;
1699 // Select x coordinate according to the anchor side
1700 if ( anchorSide
== wxRIGHT
)
1702 else if ( anchorSide
== wxLEFT
)
1707 if ( spaceBelow
< szp
.y
)
1709 popupY
= scrPos
.y
- szp
.y
;
1713 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1714 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1716 // Some platforms (GTK) may need these two to be separate
1717 winPopup
->SetSize( szp
.x
, szp
.y
);
1718 winPopup
->Move( popupX
, popupY
);
1720 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1724 // Set string selection (must be this way instead of SetStringSelection)
1727 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1728 m_text
->SelectAll();
1730 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1734 // This is neede since focus/selection indication may change when popup is shown
1738 // This must be after SetStringValue
1739 m_isPopupShown
= true;
1742 #if USE_TRANSIENT_POPUP
1743 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1748 #if INSTALL_TOPLEV_HANDLER
1749 // Put top level window event handler into place
1750 if ( !m_toplevEvtHandler
)
1751 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1753 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1755 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1756 toplev
->PushEventHandler( m_toplevEvtHandler
);
1761 void wxComboCtrlBase::OnPopupDismiss()
1763 // Just in case, avoid double dismiss
1764 if ( !m_isPopupShown
)
1767 // *Must* set this before focus etc.
1768 m_isPopupShown
= false;
1770 // Inform popup control itself
1771 m_popupInterface
->OnDismiss();
1773 if ( m_popupExtraHandler
)
1774 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1776 #if INSTALL_TOPLEV_HANDLER
1777 // Remove top level window event handler
1778 if ( m_toplevEvtHandler
)
1780 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1782 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1786 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1788 // If cursor not on dropdown button, then clear its state
1789 // (technically not required by all ports, but do it for all just in case)
1790 if ( !m_btnArea
.Inside(ScreenToClient(::wxGetMousePosition())) )
1793 // Return parent's tab traversal flag.
1794 // See ShowPopup for notes.
1795 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1797 wxWindow
* parent
= GetParent();
1798 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1799 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1802 // refresh control (necessary even if m_text)
1811 void wxComboCtrlBase::HidePopup()
1813 // Should be able to call this without popup interface
1814 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1815 if ( !m_isPopupShown
)
1818 // transfer value and show it in textctrl, if any
1819 SetValue( m_popupInterface
->GetStringValue() );
1821 #if USE_TRANSIENT_POPUP
1822 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1830 // ----------------------------------------------------------------------------
1831 // customization methods
1832 // ----------------------------------------------------------------------------
1834 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1835 int side
, int spacingX
)
1840 m_btnSpacingX
= spacingX
;
1845 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1847 const wxBitmap
& bmpPressed
,
1848 const wxBitmap
& bmpHover
,
1849 const wxBitmap
& bmpDisabled
)
1851 m_bmpNormal
= bmpNormal
;
1852 m_blankButtonBg
= blankButtonBg
;
1854 if ( bmpPressed
.Ok() )
1855 m_bmpPressed
= bmpPressed
;
1857 m_bmpPressed
= bmpNormal
;
1859 if ( bmpHover
.Ok() )
1860 m_bmpHover
= bmpHover
;
1862 m_bmpHover
= bmpNormal
;
1864 if ( bmpDisabled
.Ok() )
1865 m_bmpDisabled
= bmpDisabled
;
1867 m_bmpDisabled
= bmpNormal
;
1872 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1876 // move textctrl accordingly
1877 wxRect r
= m_text
->GetRect();
1878 int inc
= width
- m_widthCustomPaint
;
1881 m_text
->SetSize( r
);
1884 m_widthCustomPaint
= width
;
1889 void wxComboCtrlBase::SetTextIndent( int indent
)
1893 m_absIndent
= GetNativeTextIndent();
1894 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1898 m_absIndent
= indent
;
1899 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1905 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1907 return DEFAULT_TEXT_INDENT
;
1910 // ----------------------------------------------------------------------------
1911 // methods forwarded to wxTextCtrl
1912 // ----------------------------------------------------------------------------
1914 wxString
wxComboCtrlBase::GetValue() const
1917 return m_text
->GetValue();
1918 return m_valueString
;
1921 void wxComboCtrlBase::SetValue(const wxString
& value
)
1925 m_text
->SetValue(value
);
1926 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1927 m_text
->SelectAll();
1930 m_valueString
= value
;
1934 // Since wxComboPopup may want to paint the combo as well, we need
1935 // to set the string value here (as well as sometimes in ShowPopup).
1936 if ( m_valueString
!= value
&& m_popupInterface
)
1938 m_popupInterface
->SetStringValue(value
);
1942 // In this SetValue variant wxComboPopup::SetStringValue is not called
1943 void wxComboCtrlBase::SetText(const wxString
& value
)
1945 // Unlike in SetValue(), this must be called here or
1946 // the behaviour will no be consistent in readonlys.
1947 EnsurePopupControl();
1949 m_valueString
= value
;
1954 void wxComboCtrlBase::Copy()
1960 void wxComboCtrlBase::Cut()
1966 void wxComboCtrlBase::Paste()
1972 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1975 m_text
->SetInsertionPoint(pos
);
1978 void wxComboCtrlBase::SetInsertionPointEnd()
1981 m_text
->SetInsertionPointEnd();
1984 long wxComboCtrlBase::GetInsertionPoint() const
1987 return m_text
->GetInsertionPoint();
1992 long wxComboCtrlBase::GetLastPosition() const
1995 return m_text
->GetLastPosition();
2000 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2003 m_text
->Replace(from
, to
, value
);
2006 void wxComboCtrlBase::Remove(long from
, long to
)
2009 m_text
->Remove(from
, to
);
2012 void wxComboCtrlBase::SetSelection(long from
, long to
)
2015 m_text
->SetSelection(from
, to
);
2018 void wxComboCtrlBase::Undo()
2024 #endif // wxUSE_COMBOCTRL