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"
36 #include "wx/dcbuffer.h"
37 #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
;
778 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
780 delete m_popupExtraHandler
;
784 delete m_popupInterface
;
787 RemoveEventHandler(m_extraEvtHandler
);
790 m_text
->RemoveEventHandler(m_textEvtHandler
);
792 delete m_textEvtHandler
;
793 delete m_extraEvtHandler
;
797 // ----------------------------------------------------------------------------
799 // ----------------------------------------------------------------------------
801 // Recalculates button and textctrl areas
802 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
804 wxSize sz
= GetClientSize();
805 int customBorder
= m_widthCustomBorder
;
807 int btnBorder
; // border for button only
809 // check if button should really be outside the border: we'll do it it if
810 // its platform default or bitmap+pushbutton background is used, but not if
811 // there is vertical size adjustment or horizontal spacing.
812 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
813 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
814 m_btnSpacingX
== 0 &&
817 buttonOutside
= true;
818 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
823 buttonOutside
= false;
824 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
825 btnBorder
= customBorder
;
828 // Defaul indentation
829 if ( m_absIndent
< 0 )
830 m_absIndent
= GetNativeTextIndent();
832 int butWidth
= btnWidth
;
835 butWidth
= m_btnWidDefault
;
837 m_btnWidDefault
= butWidth
;
842 // Adjust button width
844 butWidth
+= m_btnWid
;
845 else if ( m_btnWid
> 0 )
848 int butHeight
= sz
.y
;
850 butHeight
-= btnBorder
*2;
852 // Adjust button height
854 butHeight
+= m_btnHei
;
855 else if ( m_btnHei
> 0 )
856 butHeight
= m_btnHei
;
858 // Use size of normal bitmap if...
861 // button width is set to default and blank button bg is not drawn
862 if ( m_bmpNormal
.Ok() )
864 int bmpReqWidth
= m_bmpNormal
.GetWidth();
865 int bmpReqHeight
= m_bmpNormal
.GetHeight();
867 // If drawing blank button background, we need to add some margin.
868 if ( m_blankButtonBg
)
870 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
871 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
874 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
875 butWidth
= bmpReqWidth
;
876 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
877 butHeight
= bmpReqHeight
;
879 // Need to fix height?
880 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
882 int newY
= butHeight
+(customBorder
*2);
883 SetClientSize(-1,newY
);
888 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
890 m_btnSize
.x
= butWidth
;
891 m_btnSize
.y
= butHeight
;
893 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
894 m_btnArea
.y
= btnBorder
;
895 m_btnArea
.width
= butAreaWid
;
896 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
898 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
899 m_tcArea
.y
= customBorder
;
900 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
901 m_tcArea
.height
= sz
.y
- (customBorder
*2);
906 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
907 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
912 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
917 wxSize sz
= GetClientSize();
918 int customBorder
= m_widthCustomBorder
;
920 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
923 int tcSizeY
= m_text
->GetBestSize().y
;
924 int diff
= sz
.y
- tcSizeY
;
925 int y
= textCtrlYAdjust
+ (diff
/2);
927 if ( y
< customBorder
)
930 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
932 m_tcArea
.width
- COMBO_MARGIN
-
933 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
936 // Make sure textctrl doesn't exceed the bottom custom border
937 wxSize tsz
= m_text
->GetSize();
938 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
941 tsz
.y
= tsz
.y
- diff
- 1;
942 m_text
->SetSize(tsz
);
947 m_text
->SetSize( m_tcArea
.x
,
949 sz
.x
- m_btnArea
.x
- m_widthCustomPaint
- customBorder
,
954 wxSize
wxComboCtrlBase::DoGetBestSize() const
956 wxSize
sizeText(150,0);
959 sizeText
= m_text
->GetBestSize();
961 // TODO: Better method to calculate close-to-native control height.
965 fhei
= (m_font
.GetPointSize()*2) + 5;
966 else if ( wxNORMAL_FONT
->Ok() )
967 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
969 fhei
= sizeText
.y
+ 4;
971 // Need to force height to accomodate bitmap?
972 int btnSizeY
= m_btnSize
.y
;
973 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
976 // Control height doesn't depend on border
979 int border = m_windowStyle & wxBORDER_MASK;
980 if ( border == wxSIMPLE_BORDER )
982 else if ( border == wxNO_BORDER )
983 fhei += (m_widthCustomBorder*2);
994 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
1001 void wxComboCtrlBase::DoMoveWindow(int x
, int y
, int width
, int height
)
1003 // SetSize is called last in create, so it marks the end of creation
1004 m_iFlags
|= wxCC_IFLAG_CREATED
;
1006 wxControl::DoMoveWindow(x
, y
, width
, height
);
1009 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1014 // defined by actual wxComboCtrls
1020 // ----------------------------------------------------------------------------
1021 // standard operations
1022 // ----------------------------------------------------------------------------
1024 bool wxComboCtrlBase::Enable(bool enable
)
1026 if ( !wxControl::Enable(enable
) )
1030 m_btn
->Enable(enable
);
1032 m_text
->Enable(enable
);
1037 bool wxComboCtrlBase::Show(bool show
)
1039 if ( !wxControl::Show(show
) )
1051 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1053 if ( !wxControl::SetFont(font
) )
1057 m_text
->SetFont(font
);
1063 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1065 wxControl::DoSetToolTip(tooltip
);
1067 // Set tool tip for button and text box
1070 const wxString
&tip
= tooltip
->GetTip();
1071 if ( m_text
) m_text
->SetToolTip(tip
);
1072 if ( m_btn
) m_btn
->SetToolTip(tip
);
1076 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1077 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1080 #endif // wxUSE_TOOLTIPS
1082 // ----------------------------------------------------------------------------
1084 // ----------------------------------------------------------------------------
1086 // draw focus background on area in a way typical on platform
1087 void wxComboCtrlBase::DrawFocusBackground( wxDC
& dc
, const wxRect
& rect
, int flags
)
1089 wxSize sz
= GetClientSize();
1091 bool isFocused
; // also selected
1093 // For smaller size control (and for disabled background) use less spacing
1097 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1100 isEnabled
= IsEnabled();
1101 isFocused
= ShouldDrawFocus();
1103 // Windows-style: for smaller size control (and for disabled background) use less spacing
1104 focusSpacingX
= isEnabled
? 2 : 1;
1105 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1109 // Drawing a list item
1110 isEnabled
= true; // they are never disabled
1111 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1117 // Set the background sub-rectangle for selection, disabled etc
1118 wxRect
selRect(rect
);
1119 selRect
.y
+= focusSpacingY
;
1120 selRect
.height
-= (focusSpacingY
*2);
1121 selRect
.x
+= m_widthCustomPaint
+ focusSpacingX
;
1122 selRect
.width
-= m_widthCustomPaint
+ (focusSpacingX
*2);
1128 // If popup is hidden and this control is focused,
1129 // then draw the focus-indicator (selbgcolor background etc.).
1132 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1133 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1137 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1138 bgCol
= GetBackgroundColour();
1143 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1144 bgCol
= GetBackgroundColour();
1147 dc
.SetBrush( bgCol
);
1149 dc
.DrawRectangle( selRect
);
1152 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1154 int drawState
= m_btnState
;
1157 if ( m_isPopupShown
)
1158 drawState
|= wxCONTROL_PRESSED
;
1161 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1162 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1166 // Make sure area is not larger than the control
1167 if ( drawRect
.y
< rect
.y
)
1168 drawRect
.y
= rect
.y
;
1169 if ( drawRect
.height
> rect
.height
)
1170 drawRect
.height
= rect
.height
;
1172 bool enabled
= IsEnabled();
1175 drawState
|= wxCONTROL_DISABLED
;
1177 if ( !m_bmpNormal
.Ok() )
1179 // Need to clear button background even if m_btn is present
1184 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1185 bgCol
= GetParent()->GetBackgroundColour();
1187 bgCol
= GetBackgroundColour();
1191 dc
.DrawRectangle(rect
);
1194 // Draw standard button
1195 wxRendererNative::Get().DrawComboBoxDropButton(this,
1207 pBmp
= &m_bmpDisabled
;
1208 else if ( m_btnState
& wxCONTROL_PRESSED
)
1209 pBmp
= &m_bmpPressed
;
1210 else if ( m_btnState
& wxCONTROL_CURRENT
)
1213 pBmp
= &m_bmpNormal
;
1215 if ( m_blankButtonBg
)
1217 // If using blank button background, we need to clear its background
1218 // with button face colour instead of colour for rest of the control.
1221 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1222 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1225 dc
.DrawRectangle(rect
);
1228 wxRendererNative::Get().DrawPushButton(this,
1237 // Need to clear button background even if m_btn is present
1238 // (assume non-button background was cleared just before this call so brushes are good)
1240 dc
.DrawRectangle(rect
);
1243 // Draw bitmap centered in drawRect
1244 dc
.DrawBitmap(*pBmp
,
1245 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1246 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1251 void wxComboCtrlBase::RecalcAndRefresh()
1255 wxSizeEvent
evt(GetSize(),GetId());
1256 GetEventHandler()->ProcessEvent(evt
);
1261 wxBitmap
& wxComboCtrlBase::GetBufferBitmap( const wxSize
& sz
) const
1263 // If size is larger, recalculate double buffer bitmap
1264 if ( !gs_doubleBuffer
||
1265 sz
.x
> gs_doubleBuffer
->GetWidth() ||
1266 sz
.y
> gs_doubleBuffer
->GetHeight() )
1268 delete gs_doubleBuffer
;
1269 gs_doubleBuffer
= new wxBitmap(sz
.x
+25,sz
.y
);
1271 return *gs_doubleBuffer
;
1274 // ----------------------------------------------------------------------------
1275 // miscellaneous event handlers
1276 // ----------------------------------------------------------------------------
1278 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1280 // Change event id and relay it forward
1281 event
.SetId(GetId());
1285 // call if cursor is on button area or mouse is captured for the button
1286 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1289 int type
= event
.GetEventType();
1291 if ( type
== wxEVT_MOTION
)
1293 if ( flags
& wxCC_MF_ON_BUTTON
)
1295 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1297 // Mouse hover begins
1298 m_btnState
|= wxCONTROL_CURRENT
;
1299 if ( HasCapture() ) // Retain pressed state.
1300 m_btnState
|= wxCONTROL_PRESSED
;
1304 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1307 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1311 else if ( type
== wxEVT_LEFT_DOWN
)
1313 // Only accept event if it wasn't right after popup dismiss
1314 //if ( ::wxGetLocalTimeMillis() > m_timeCanClick )
1316 // Need to test this, because it might be outside.
1317 if ( flags
& wxCC_MF_ON_BUTTON
)
1319 m_btnState
|= wxCONTROL_PRESSED
;
1322 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1325 // If showing popup now, do not capture mouse or there will be interference
1334 else if ( type
== wxEVT_LEFT_UP
)
1337 // Only accept event if mouse was left-press was previously accepted
1341 if ( m_btnState
& wxCONTROL_PRESSED
)
1343 // If mouse was inside, fire the click event.
1344 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1346 if ( flags
& wxCC_MF_ON_BUTTON
)
1350 m_btnState
&= ~(wxCONTROL_PRESSED
);
1354 else if ( type
== wxEVT_LEAVE_WINDOW
)
1356 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1358 m_btnState
&= ~(wxCONTROL_CURRENT
);
1361 if ( !m_isPopupShown
)
1363 m_btnState
&= ~(wxCONTROL_PRESSED
);
1374 // Conversion to double-clicks and some basic filtering
1375 // returns true if event was consumed or filtered
1376 //bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea )
1377 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1380 wxLongLong t
= ::wxGetLocalTimeMillis();
1381 int evtType
= event
.GetEventType();
1384 // Generate our own double-clicks
1385 // (to allow on-focus dc-event on double-clicks instead of triple-clicks)
1386 if ( (m_windowStyle
& wxCC_SPECIAL_DCLICK
) &&
1388 //!(handlerFlags & wxCC_MF_ON_BUTTON) )
1389 !(flags
& wxCC_MF_ON_BUTTON
) )
1391 if ( evtType
== wxEVT_LEFT_DOWN
)
1393 // Set value to avoid up-events without corresponding downs
1394 m_downReceived
= true;
1396 else if ( evtType
== wxEVT_LEFT_DCLICK
)
1398 // We'll make our own double-clicks
1400 event
.SetEventType(0);
1403 else if ( evtType
== wxEVT_LEFT_UP
)
1405 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
1407 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
1409 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
1411 //type = wxEVT_LEFT_DCLICK;
1412 event
.SetEventType(wxEVT_LEFT_DCLICK
);
1413 m_timeLastMouseUp
= 1;
1417 m_timeLastMouseUp
= t
;
1420 //m_downReceived = false;
1425 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1426 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1428 event
.SetEventType(0);
1435 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1437 int evtType
= event
.GetEventType();
1439 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1440 (m_windowStyle
& wxCB_READONLY
) )
1442 if ( m_isPopupShown
)
1445 // Normally do nothing - evt handler should close it for us
1446 #elif !USE_TRANSIENT_POPUP
1447 // Click here always hides the popup.
1453 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1455 // In read-only mode, clicking the text is the
1456 // same as clicking the button.
1459 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1461 //if ( m_popupInterface->CycleValue() )
1463 if ( m_popupInterface
)
1464 m_popupInterface
->OnComboDoubleClick();
1469 if ( m_isPopupShown
)
1471 // relay (some) mouse events to the popup
1472 if ( evtType
== wxEVT_MOUSEWHEEL
)
1473 m_popup
->AddPendingEvent(event
);
1479 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& )
1481 // First click is the first part of double-click
1482 // Some platforms don't generate down-less mouse up-event
1483 // (Windows does, GTK+2 doesn't), so that's why we have
1485 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
1492 // no need to check for m_widthCustomPaint - that
1493 // area never gets special handling when selected
1494 // (in writable mode, that is)
1498 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1501 // indentation may also have changed
1502 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1503 m_absIndent
= GetNativeTextIndent();
1507 // ----------------------------------------------------------------------------
1509 // ----------------------------------------------------------------------------
1511 // Create popup window and the child control
1512 void wxComboCtrlBase::CreatePopup()
1514 wxComboPopup
* popupInterface
= m_popupInterface
;
1518 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1520 popupInterface
->Create(m_winPopup
);
1521 m_popup
= popup
= popupInterface
->GetControl();
1523 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1524 popup
->PushEventHandler( m_popupExtraHandler
);
1526 // This may be helpful on some platforms
1527 // (eg. it bypasses a wxGTK popupwindow bug where
1528 // window is not initially hidden when it should be)
1531 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1534 void wxComboCtrlBase::SetPopupControl( wxComboPopup
* iface
)
1536 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1538 delete m_popupInterface
;
1541 iface
->InitBase(this);
1544 m_popupInterface
= iface
;
1546 if ( !iface
->LazyCreate() || m_winPopup
)
1552 m_popup
= (wxWindow
*) NULL
;
1555 // This must be done after creation
1556 if ( m_valueString
.length() )
1558 iface
->SetStringValue(m_valueString
);
1563 // Ensures there is atleast the default popup
1564 void wxComboCtrlBase::EnsurePopupControl()
1566 if ( !m_popupInterface
)
1567 SetPopupControl(NULL
);
1570 void wxComboCtrlBase::OnButtonClick()
1572 // Derived classes can override this method for totally custom
1577 void wxComboCtrlBase::ShowPopup()
1579 EnsurePopupControl();
1580 wxCHECK_RET( !IsPopupShown(), wxT("popup window already shown") );
1584 // Space above and below
1590 wxSize ctrlSz
= GetSize();
1592 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1593 scrPos
= GetParent()->ClientToScreen(GetPosition());
1595 spaceAbove
= scrPos
.y
;
1596 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1598 maxHeightPopup
= spaceBelow
;
1599 if ( spaceAbove
> spaceBelow
)
1600 maxHeightPopup
= spaceAbove
;
1603 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1605 if ( widthPopup
< m_widthMinPopup
)
1606 widthPopup
= m_widthMinPopup
;
1608 wxWindow
* winPopup
= m_winPopup
;
1611 // Need to disable tab traversal of parent
1613 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1614 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1615 // that if transient popup is open, then tab traversal is to be ignored.
1616 // However, I think this code would still be needed for cases where
1617 // transient popup doesn't work yet (wxWinCE?).
1618 wxWindow
* parent
= GetParent();
1619 int parentFlags
= parent
->GetWindowStyle();
1620 if ( parentFlags
& wxTAB_TRAVERSAL
)
1622 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1623 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1629 winPopup
= m_winPopup
;
1637 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1639 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1640 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1643 popup
->SetSize(adjustedSize
);
1645 m_popupInterface
->OnPopup();
1648 // Reposition and resize popup window
1651 wxSize szp
= popup
->GetSize();
1654 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1656 int anchorSide
= m_anchorSide
;
1658 anchorSide
= m_btnSide
;
1660 // Anchor popup to the side the dropbutton is on
1661 if ( anchorSide
== wxRIGHT
)
1662 popupX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1664 popupX
= scrPos
.x
- m_extLeft
;
1666 if ( spaceBelow
< szp
.y
)
1668 popupY
= scrPos
.y
- szp
.y
;
1672 //wxLogDebug(wxT("popup scheduled position1: %i,%i"),ptp.x,ptp.y);
1673 //wxLogDebug(wxT("popup position1: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1675 // Some platforms (GTK) may need these two to be separate
1676 winPopup
->SetSize( szp
.x
, szp
.y
);
1677 winPopup
->Move( popupX
, popupY
);
1679 //wxLogDebug(wxT("popup position2: %i,%i"),winPopup->GetPosition().x,winPopup->GetPosition().y);
1683 // Set string selection (must be this way instead of SetStringSelection)
1686 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1687 m_text
->SelectAll();
1689 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1693 // This is neede since focus/selection indication may change when popup is shown
1697 // This must be after SetStringValue
1698 m_isPopupShown
= true;
1701 #if USE_TRANSIENT_POPUP
1702 ((wxPopupTransientWindow
*)winPopup
)->Popup(popup
);
1707 #if INSTALL_TOPLEV_HANDLER
1708 // Put top level window event handler into place
1709 if ( !m_toplevEvtHandler
)
1710 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1712 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1714 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1715 toplev
->PushEventHandler( m_toplevEvtHandler
);
1720 void wxComboCtrlBase::OnPopupDismiss()
1722 // Just in case, avoid double dismiss
1723 if ( !m_isPopupShown
)
1726 // *Must* set this before focus etc.
1727 m_isPopupShown
= false;
1729 // Inform popup control itself
1730 m_popupInterface
->OnDismiss();
1732 if ( m_popupExtraHandler
)
1733 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1735 #if INSTALL_TOPLEV_HANDLER
1736 // Remove top level window event handler
1737 if ( m_toplevEvtHandler
)
1739 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1741 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1745 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis() + 150;
1747 // If cursor not on dropdown button, then clear its state
1748 // (technically not required by all ports, but do it for all just in case)
1749 if ( !m_btnArea
.Inside(ScreenToClient(::wxGetMousePosition())) )
1752 // Return parent's tab traversal flag.
1753 // See ShowPopup for notes.
1754 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1756 wxWindow
* parent
= GetParent();
1757 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1758 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1761 // refresh control (necessary even if m_text)
1770 void wxComboCtrlBase::HidePopup()
1772 // Should be able to call this without popup interface
1773 //wxCHECK_RET( m_popupInterface, _T("no popup interface") );
1774 if ( !m_isPopupShown
)
1777 // transfer value and show it in textctrl, if any
1778 SetValue( m_popupInterface
->GetStringValue() );
1780 #if USE_TRANSIENT_POPUP
1781 ((wxPopupTransientWindow
*)m_winPopup
)->Dismiss();
1789 // ----------------------------------------------------------------------------
1790 // customization methods
1791 // ----------------------------------------------------------------------------
1793 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
1794 int side
, int spacingX
)
1799 m_btnSpacingX
= spacingX
;
1804 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
1806 const wxBitmap
& bmpPressed
,
1807 const wxBitmap
& bmpHover
,
1808 const wxBitmap
& bmpDisabled
)
1810 m_bmpNormal
= bmpNormal
;
1811 m_blankButtonBg
= blankButtonBg
;
1813 if ( bmpPressed
.Ok() )
1814 m_bmpPressed
= bmpPressed
;
1816 m_bmpPressed
= bmpNormal
;
1818 if ( bmpHover
.Ok() )
1819 m_bmpHover
= bmpHover
;
1821 m_bmpHover
= bmpNormal
;
1823 if ( bmpDisabled
.Ok() )
1824 m_bmpDisabled
= bmpDisabled
;
1826 m_bmpDisabled
= bmpNormal
;
1831 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
1835 // move textctrl accordingly
1836 wxRect r
= m_text
->GetRect();
1837 int inc
= width
- m_widthCustomPaint
;
1840 m_text
->SetSize( r
);
1843 m_widthCustomPaint
= width
;
1848 void wxComboCtrlBase::SetTextIndent( int indent
)
1852 m_absIndent
= GetNativeTextIndent();
1853 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
1857 m_absIndent
= indent
;
1858 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
1864 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
1866 return DEFAULT_TEXT_INDENT
;
1869 // ----------------------------------------------------------------------------
1870 // methods forwarded to wxTextCtrl
1871 // ----------------------------------------------------------------------------
1873 wxString
wxComboCtrlBase::GetValue() const
1876 return m_text
->GetValue();
1877 return m_valueString
;
1880 void wxComboCtrlBase::SetValue(const wxString
& value
)
1884 m_text
->SetValue(value
);
1885 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1886 m_text
->SelectAll();
1889 m_valueString
= value
;
1893 // Since wxComboPopup may want to paint the combo as well, we need
1894 // to set the string value here (as well as sometimes in ShowPopup).
1895 if ( m_valueString
!= value
&& m_popupInterface
)
1897 m_popupInterface
->SetStringValue(value
);
1901 // In this SetValue variant wxComboPopup::SetStringValue is not called
1902 void wxComboCtrlBase::SetText(const wxString
& value
)
1904 // Unlike in SetValue(), this must be called here or
1905 // the behaviour will no be consistent in readonlys.
1906 EnsurePopupControl();
1908 m_valueString
= value
;
1913 void wxComboCtrlBase::Copy()
1919 void wxComboCtrlBase::Cut()
1925 void wxComboCtrlBase::Paste()
1931 void wxComboCtrlBase::SetInsertionPoint(long pos
)
1934 m_text
->SetInsertionPoint(pos
);
1937 void wxComboCtrlBase::SetInsertionPointEnd()
1940 m_text
->SetInsertionPointEnd();
1943 long wxComboCtrlBase::GetInsertionPoint() const
1946 return m_text
->GetInsertionPoint();
1951 long wxComboCtrlBase::GetLastPosition() const
1954 return m_text
->GetLastPosition();
1959 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
1962 m_text
->Replace(from
, to
, value
);
1965 void wxComboCtrlBase::Remove(long from
, long to
)
1968 m_text
->Remove(from
, to
);
1971 void wxComboCtrlBase::SetSelection(long from
, long to
)
1974 m_text
->SetSelection(from
, to
);
1977 void wxComboCtrlBase::Undo()
1983 #endif // wxUSE_COMBOCTRL