1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/combocmn.cpp
3 // Purpose: wxComboCtrlBase
4 // Author: Jaakko Salli
6 // Created: Apr-30-2006
8 // Copyright: (c) 2005 Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
28 #include "wx/combobox.h"
32 #include "wx/dcclient.h"
33 #include "wx/settings.h"
34 #include "wx/dialog.h"
38 #include "wx/tooltip.h"
45 // ----------------------------------------------------------------------------
47 #define DEFAULT_DROPBUTTON_WIDTH 19
49 #define BMP_BUTTON_MARGIN 4
51 #define DEFAULT_POPUP_HEIGHT 400
53 #define DEFAULT_TEXT_INDENT 3
55 #define COMBO_MARGIN 2 // spacing right of wxTextCtrl
58 #if defined(__WXMSW__)
60 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
61 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
62 // native controls work on it like normal.
63 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
64 #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered
66 //#undef wxUSE_POPUPWIN
67 //#define wxUSE_POPUPWIN 0
69 #elif defined(__WXGTK__)
71 // NB: It is not recommended to use wxDialog as popup on wxGTK, because of
72 // this bug: If wxDialog is hidden, its position becomes corrupt
73 // between hide and next show, but without internal coordinates being
74 // reflected (or something like that - atleast commenting out ->Hide()
75 // seemed to eliminate the position change).
77 #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
78 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
79 // native controls work on it like normal.
80 #define POPUPWIN_IS_PERFECT 1 // Same, but for non-transient popup window.
81 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
83 #elif defined(__WXMAC__)
85 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
86 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
87 // native controls work on it like normal.
88 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
89 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
93 #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform)
94 #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common
95 // native controls work on it like normal.
96 #define POPUPWIN_IS_PERFECT 0 // Same, but for non-transient popup window.
97 #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered
102 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
103 // what the wxUSE_POPUPWIN says.
104 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
105 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
106 #undef wxUSE_POPUPWIN
107 #define wxUSE_POPUPWIN 0
112 #include "wx/popupwin.h"
114 #undef USE_TRANSIENT_POPUP
115 #define USE_TRANSIENT_POPUP 0
119 // Define different types of popup windows
123 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
124 POPUPWIN_WXPOPUPWINDOW
= 2,
125 POPUPWIN_WXDIALOG
= 3
129 #if USE_TRANSIENT_POPUP
130 // wxPopupTransientWindow is implemented
132 #define wxComboPopupWindowBase wxPopupTransientWindow
133 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
134 #define USES_WXPOPUPTRANSIENTWINDOW 1
136 #if TRANSIENT_POPUPWIN_IS_PERFECT
138 #elif POPUPWIN_IS_PERFECT
139 #define wxComboPopupWindowBase2 wxPopupWindow
140 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
141 #define USES_WXPOPUPWINDOW 1
143 #define wxComboPopupWindowBase2 wxDialog
144 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
145 #define USES_WXDIALOG 1
149 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
151 #define wxComboPopupWindowBase wxPopupWindow
152 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
153 #define USES_WXPOPUPWINDOW 1
155 #if !POPUPWIN_IS_PERFECT
156 #define wxComboPopupWindowBase2 wxDialog
157 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
158 #define USES_WXDIALOG 1
162 // wxPopupWindow is not implemented
164 #define wxComboPopupWindowBase wxDialog
165 #define PRIMARY_POPUP_TYPE POPUPWIN_WXDIALOG
166 #define USES_WXDIALOG 1
171 #ifndef USES_WXPOPUPTRANSIENTWINDOW
172 #define USES_WXPOPUPTRANSIENTWINDOW 0
175 #ifndef USES_WXPOPUPWINDOW
176 #define USES_WXPOPUPWINDOW 0
179 #ifndef USES_WXDIALOG
180 #define USES_WXDIALOG 0
184 #if USES_WXPOPUPWINDOW
185 #define INSTALL_TOPLEV_HANDLER 1
187 #define INSTALL_TOPLEV_HANDLER 0
193 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
197 // ----------------------------------------------------------------------------
198 // wxComboFrameEventHandler takes care of hiding the popup when events happen
199 // in its top level parent.
200 // ----------------------------------------------------------------------------
202 #if INSTALL_TOPLEV_HANDLER
205 // This will no longer be necessary after wxTransientPopupWindow
206 // works well on all platforms.
209 class wxComboFrameEventHandler
: public wxEvtHandler
212 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
213 virtual ~wxComboFrameEventHandler();
217 void OnIdle( wxIdleEvent
& event
);
218 void OnMouseEvent( wxMouseEvent
& event
);
219 void OnActivate( wxActivateEvent
& event
);
220 void OnResize( wxSizeEvent
& event
);
221 void OnMove( wxMoveEvent
& event
);
222 void OnMenuEvent( wxMenuEvent
& event
);
223 void OnClose( wxCloseEvent
& event
);
226 wxWindow
* m_focusStart
;
227 wxComboCtrlBase
* m_combo
;
230 DECLARE_EVENT_TABLE()
233 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
234 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
235 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
236 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
237 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
238 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
239 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
240 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
241 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
242 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
245 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
251 wxComboFrameEventHandler::~wxComboFrameEventHandler()
255 void wxComboFrameEventHandler::OnPopup()
257 m_focusStart
= ::wxWindow::FindFocus();
260 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
262 wxWindow
* winFocused
= ::wxWindow::FindFocus();
264 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
265 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
268 winFocused
!= m_focusStart
&&
269 winFocused
!= popup
&&
270 winFocused
->GetParent() != popup
&&
271 winFocused
!= winpopup
&&
272 winFocused
->GetParent() != winpopup
&&
273 winFocused
!= m_combo
&&
274 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
277 m_combo
->HidePopup();
283 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
285 m_combo
->HidePopup();
289 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
291 m_combo
->HidePopup();
295 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
297 m_combo
->HidePopup();
301 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
303 m_combo
->HidePopup();
307 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
309 m_combo
->HidePopup();
313 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
315 m_combo
->HidePopup();
319 #endif // INSTALL_TOPLEV_HANDLER
321 // ----------------------------------------------------------------------------
322 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
324 // ----------------------------------------------------------------------------
326 class wxComboPopupWindow
: public wxComboPopupWindowBase
330 wxComboPopupWindow( wxComboCtrlBase
*parent
,
332 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
333 : wxComboPopupWindowBase(parent
,style
)
335 : wxComboPopupWindowBase(parent
,
346 #if USES_WXPOPUPTRANSIENTWINDOW
347 virtual bool Show( bool show
);
348 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
349 virtual void OnDismiss();
357 #if USES_WXPOPUPTRANSIENTWINDOW
358 bool wxComboPopupWindow::Show( bool show
)
360 // Guard against recursion
362 return wxComboPopupWindowBase::Show(show
);
366 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
368 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
369 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
371 if ( show
!= ptw
->IsShown() )
374 ptw
->Popup(combo
->GetPopupControl()->GetControl());
384 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
386 return wxPopupTransientWindow::ProcessLeftDown(event
);
389 // First thing that happens when a transient popup closes is that this method gets called.
390 void wxComboPopupWindow::OnDismiss()
392 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
393 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
394 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
396 combo
->OnPopupDismiss();
398 #endif // USES_WXPOPUPTRANSIENTWINDOW
401 // ----------------------------------------------------------------------------
402 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
403 // of a popup window. It is separate so we can have different types
405 // ----------------------------------------------------------------------------
407 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
411 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
416 void OnSizeEvent( wxSizeEvent
& event
);
417 void OnKeyEvent(wxKeyEvent
& event
);
419 void OnActivate( wxActivateEvent
& event
);
423 wxComboCtrlBase
* m_combo
;
425 DECLARE_EVENT_TABLE()
429 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
430 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
431 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
433 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
435 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
439 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
441 // Block the event so that the popup control does not get auto-resized.
444 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
446 // Relay keyboard event to the main child controls
447 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
448 wxWindowList::iterator node
= children
.begin();
449 wxWindow
* child
= (wxWindow
*)*node
;
450 child
->AddPendingEvent(event
);
454 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
456 if ( !event
.GetActive() )
458 // Tell combo control that we are dismissed.
459 m_combo
->HidePopup();
467 // ----------------------------------------------------------------------------
470 // ----------------------------------------------------------------------------
472 wxComboPopup::~wxComboPopup()
476 void wxComboPopup::OnPopup()
480 void wxComboPopup::OnDismiss()
484 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
486 int WXUNUSED(maxHeight
) )
488 return wxSize(minWidth
,prefHeight
);
491 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
492 wxDC
& dc
, const wxRect
& rect
)
494 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
496 combo
->PrepareBackground(dc
,rect
,0);
498 dc
.DrawText( combo
->GetValue(),
499 rect
.x
+ combo
->GetTextIndent(),
500 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
504 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
506 DefaultPaintComboControl(m_combo
,dc
,rect
);
509 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
514 void wxComboPopup::OnComboDoubleClick()
518 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
522 bool wxComboPopup::LazyCreate()
527 void wxComboPopup::Dismiss()
529 m_combo
->HidePopup();
532 // ----------------------------------------------------------------------------
534 // ----------------------------------------------------------------------------
537 // This is pushed to the event handler queue of the child textctrl.
539 class wxComboBoxExtraInputHandler
: public wxEvtHandler
543 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
548 virtual ~wxComboBoxExtraInputHandler() { }
549 void OnKey(wxKeyEvent
& event
);
550 void OnFocus(wxFocusEvent
& event
);
553 wxComboCtrlBase
* m_combo
;
556 DECLARE_EVENT_TABLE()
560 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
561 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
562 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
566 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
568 // Let the wxComboCtrl event handler have a go first.
569 wxComboCtrlBase
* combo
= m_combo
;
570 wxObject
* prevObj
= event
.GetEventObject();
572 event
.SetId(combo
->GetId());
573 event
.SetEventObject(combo
);
574 combo
->GetEventHandler()->ProcessEvent(event
);
576 event
.SetId(((wxWindow
*)prevObj
)->GetId());
577 event
.SetEventObject(prevObj
);
580 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
582 // FIXME: This code does run when control is clicked,
583 // yet on Windows it doesn't select all the text.
584 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
586 if ( m_combo
->GetTextCtrl() )
587 m_combo
->GetTextCtrl()->SelectAll();
589 m_combo
->SetSelection(-1,-1);
592 // Send focus indication to parent.
593 // NB: This is needed for cases where the textctrl gets focus
594 // instead of its parent. While this may trigger multiple
595 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
596 // from combo's focus event handler), they should be quite
598 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
599 evt2
.SetEventObject(m_combo
);
600 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
607 // This is pushed to the event handler queue of the control in popup.
610 class wxComboPopupExtraEventHandler
: public wxEvtHandler
614 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
618 m_beenInside
= false;
620 virtual ~wxComboPopupExtraEventHandler() { }
622 void OnMouseEvent( wxMouseEvent
& event
);
624 // Called from wxComboCtrlBase::OnPopupDismiss
625 void OnPopupDismiss()
627 m_beenInside
= false;
631 wxComboCtrlBase
* m_combo
;
636 DECLARE_EVENT_TABLE()
640 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
641 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
645 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
647 wxPoint pt
= event
.GetPosition();
648 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
649 int evtType
= event
.GetEventType();
650 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
652 if ( evtType
== wxEVT_MOTION
||
653 evtType
== wxEVT_LEFT_DOWN
||
654 evtType
== wxEVT_RIGHT_DOWN
)
656 // Block motion and click events outside the popup
657 if ( !isInside
|| !m_combo
->IsPopupShown() )
663 else if ( evtType
== wxEVT_LEFT_UP
)
665 if ( !m_combo
->IsPopupShown() )
680 // Some mouse events to popup that happen outside it, before cursor
681 // has been inside the popu, need to be ignored by it but relayed to
684 wxWindow
* btn
= m_combo
->GetButton();
686 btn
->GetEventHandler()->AddPendingEvent(event
);
688 m_combo
->GetEventHandler()->AddPendingEvent(event
);
700 // ----------------------------------------------------------------------------
702 // ----------------------------------------------------------------------------
705 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
706 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
707 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
708 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
709 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
710 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
711 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
712 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
713 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
717 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
719 void wxComboCtrlBase::Init()
721 m_winPopup
= (wxWindow
*)NULL
;
722 m_popup
= (wxWindow
*)NULL
;
723 m_popupWinState
= Hidden
;
724 m_btn
= (wxWindow
*) NULL
;
725 m_text
= (wxTextCtrl
*) NULL
;
726 m_popupInterface
= (wxComboPopup
*) NULL
;
728 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
729 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
731 #if INSTALL_TOPLEV_HANDLER
732 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
735 m_mainCtrlWnd
= this;
738 m_widthMinPopup
= -1;
740 m_widthCustomPaint
= 0;
741 m_widthCustomBorder
= 0;
745 m_blankButtonBg
= false;
747 m_popupWinType
= POPUPWIN_NONE
;
748 m_btnWid
= m_btnHei
= -1;
756 m_timeCanAcceptClick
= 0;
759 bool wxComboCtrlBase::Create(wxWindow
*parent
,
761 const wxString
& value
,
765 const wxValidator
& validator
,
766 const wxString
& name
)
768 if ( !wxControl::Create(parent
,
772 style
| wxWANTS_CHARS
,
777 m_valueString
= value
;
781 m_absIndent
= GetNativeTextIndent();
783 m_iFlags
|= wxCC_IFLAG_CREATED
;
785 // If x and y indicate valid size, wxSizeEvent won't be
786 // emitted automatically, so we need to add artifical one.
787 if ( size
.x
> 0 && size
.y
> 0 )
789 wxSizeEvent
evt(size
,GetId());
790 GetEventHandler()->AddPendingEvent(evt
);
796 void wxComboCtrlBase::InstallInputHandlers()
800 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
801 m_text
->PushEventHandler(m_textEvtHandler
);
806 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
808 if ( !(m_windowStyle
& wxCB_READONLY
) )
813 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
814 // not used by the wxPropertyGrid and therefore the tab is processed by
815 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
816 // navigation event is then sent to the wrong window.
817 style
|= wxTE_PROCESS_TAB
;
819 if ( HasFlag(wxTE_PROCESS_ENTER
) )
820 style
|= wxTE_PROCESS_ENTER
;
822 // Ignore EVT_TEXT generated by the constructor (but only
823 // if the event redirector already exists)
824 // NB: This must be " = 1" instead of "++";
825 if ( m_textEvtHandler
)
830 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
831 wxDefaultPosition
, wxDefaultSize
,
834 // This is required for some platforms (GTK+ atleast)
835 m_text
->SetSizeHints(2,4);
839 void wxComboCtrlBase::OnThemeChange()
841 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
844 wxComboCtrlBase::~wxComboCtrlBase()
849 #if INSTALL_TOPLEV_HANDLER
850 delete ((wxComboFrameEventHandler
*)m_toplevEvtHandler
);
851 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
857 m_text
->RemoveEventHandler(m_textEvtHandler
);
859 delete m_textEvtHandler
;
863 // ----------------------------------------------------------------------------
865 // ----------------------------------------------------------------------------
867 // Recalculates button and textctrl areas
868 void wxComboCtrlBase::CalculateAreas( int btnWidth
)
870 wxSize sz
= GetClientSize();
871 int customBorder
= m_widthCustomBorder
;
872 int btnBorder
; // border for button only
874 // check if button should really be outside the border: we'll do it it if
875 // its platform default or bitmap+pushbutton background is used, but not if
876 // there is vertical size adjustment or horizontal spacing.
877 if ( ( (m_iFlags
& wxCC_BUTTON_OUTSIDE_BORDER
) ||
878 (m_bmpNormal
.Ok() && m_blankButtonBg
) ) &&
879 m_btnSpacingX
== 0 &&
882 m_iFlags
|= wxCC_IFLAG_BUTTON_OUTSIDE
;
887 m_iFlags
&= ~(wxCC_IFLAG_BUTTON_OUTSIDE
);
888 btnBorder
= customBorder
;
891 // Defaul indentation
892 if ( m_absIndent
< 0 )
893 m_absIndent
= GetNativeTextIndent();
895 int butWidth
= btnWidth
;
898 butWidth
= m_btnWidDefault
;
900 m_btnWidDefault
= butWidth
;
905 int butHeight
= sz
.y
- btnBorder
*2;
907 // Adjust button width
912 // Adjust button width to match aspect ratio
913 // (but only if control is smaller than best size).
914 int bestHeight
= GetBestSize().y
;
915 int height
= GetSize().y
;
917 if ( height
< bestHeight
)
919 // Make very small buttons square, as it makes
920 // them accommodate arrow image better and still
923 butWidth
= (height
*butWidth
)/bestHeight
;
925 butWidth
= butHeight
;
929 // Adjust button height
931 butHeight
= m_btnHei
;
933 // Use size of normal bitmap if...
936 // button width is set to default and blank button bg is not drawn
937 if ( m_bmpNormal
.Ok() )
939 int bmpReqWidth
= m_bmpNormal
.GetWidth();
940 int bmpReqHeight
= m_bmpNormal
.GetHeight();
942 // If drawing blank button background, we need to add some margin.
943 if ( m_blankButtonBg
)
945 bmpReqWidth
+= BMP_BUTTON_MARGIN
*2;
946 bmpReqHeight
+= BMP_BUTTON_MARGIN
*2;
949 if ( butWidth
< bmpReqWidth
|| ( m_btnWid
== 0 && !m_blankButtonBg
) )
950 butWidth
= bmpReqWidth
;
951 if ( butHeight
< bmpReqHeight
|| ( m_btnHei
== 0 && !m_blankButtonBg
) )
952 butHeight
= bmpReqHeight
;
954 // Need to fix height?
955 if ( (sz
.y
-(customBorder
*2)) < butHeight
&& btnWidth
== 0 )
957 int newY
= butHeight
+(customBorder
*2);
958 SetClientSize(wxDefaultCoord
,newY
);
963 int butAreaWid
= butWidth
+ (m_btnSpacingX
*2);
965 m_btnSize
.x
= butWidth
;
966 m_btnSize
.y
= butHeight
;
968 m_btnArea
.x
= ( m_btnSide
==wxRIGHT
? sz
.x
- butAreaWid
- btnBorder
: btnBorder
);
969 m_btnArea
.y
= btnBorder
;
970 m_btnArea
.width
= butAreaWid
;
971 m_btnArea
.height
= sz
.y
- (btnBorder
*2);
973 m_tcArea
.x
= ( m_btnSide
==wxRIGHT
? 0 : butAreaWid
) + customBorder
;
974 m_tcArea
.y
= customBorder
;
975 m_tcArea
.width
= sz
.x
- butAreaWid
- (customBorder
*2);
976 m_tcArea
.height
= sz
.y
- (customBorder
*2);
981 ::wxMessageBox(wxString::Format(wxT("ButtonArea (%i,%i,%i,%i)\n"),m_btnArea.x,m_btnArea.y,m_btnArea.width,m_btnArea.height) +
982 wxString::Format(wxT("TextCtrlArea (%i,%i,%i,%i)"),m_tcArea.x,m_tcArea.y,m_tcArea.width,m_tcArea.height));
987 void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust
, int textCtrlYAdjust
)
992 wxSize sz
= GetClientSize();
993 int customBorder
= m_widthCustomBorder
;
995 #if !TEXTCTRL_TEXT_CENTERED
996 if ( (m_text
->GetWindowStyleFlag() & wxBORDER_MASK
) == wxNO_BORDER
)
999 int tcSizeY
= m_text
->GetBestSize().y
;
1000 int diff
= sz
.y
- tcSizeY
;
1001 int y
= textCtrlYAdjust
+ (diff
/2);
1003 if ( y
< customBorder
)
1006 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
+ m_absIndent
+ textCtrlXAdjust
,
1008 m_tcArea
.width
- COMBO_MARGIN
-
1009 (textCtrlXAdjust
+ m_widthCustomPaint
+ m_absIndent
),
1012 // Make sure textctrl doesn't exceed the bottom custom border
1013 wxSize tsz
= m_text
->GetSize();
1014 diff
= (y
+ tsz
.y
) - (sz
.y
- customBorder
);
1017 tsz
.y
= tsz
.y
- diff
- 1;
1018 m_text
->SetSize(tsz
);
1023 wxUnusedVar(textCtrlXAdjust
);
1024 wxUnusedVar(textCtrlYAdjust
);
1027 // If it has border, have textctrl will the entire text field.
1028 m_text
->SetSize( m_tcArea
.x
+ m_widthCustomPaint
,
1030 sz
.x
- m_btnArea
.width
- m_widthCustomPaint
- customBorder
,
1031 sz
.y
-(customBorder
*2) );
1035 wxSize
wxComboCtrlBase::DoGetBestSize() const
1037 wxSize
sizeText(150,0);
1040 sizeText
= m_text
->GetBestSize();
1042 // TODO: Better method to calculate close-to-native control height.
1046 fhei
= (m_font
.GetPointSize()*2) + 5;
1047 else if ( wxNORMAL_FONT
->Ok() )
1048 fhei
= (wxNORMAL_FONT
->GetPointSize()*2) + 5;
1050 fhei
= sizeText
.y
+ 4;
1052 // Need to force height to accomodate bitmap?
1053 int btnSizeY
= m_btnSize
.y
;
1054 if ( m_bmpNormal
.Ok() && fhei
< btnSizeY
)
1057 // Control height doesn't depend on border
1060 int border = m_windowStyle & wxBORDER_MASK;
1061 if ( border == wxSIMPLE_BORDER )
1063 else if ( border == wxNO_BORDER )
1064 fhei += (m_widthCustomBorder*2);
1070 // Final adjustments
1075 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
1082 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1087 // defined by actual wxComboCtrls
1093 // ----------------------------------------------------------------------------
1094 // standard operations
1095 // ----------------------------------------------------------------------------
1097 bool wxComboCtrlBase::Enable(bool enable
)
1099 if ( !wxControl::Enable(enable
) )
1103 m_btn
->Enable(enable
);
1105 m_text
->Enable(enable
);
1110 bool wxComboCtrlBase::Show(bool show
)
1112 if ( !wxControl::Show(show
) )
1124 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1126 if ( !wxControl::SetFont(font
) )
1130 m_text
->SetFont(font
);
1136 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1138 wxControl::DoSetToolTip(tooltip
);
1140 // Set tool tip for button and text box
1143 const wxString
&tip
= tooltip
->GetTip();
1144 if ( m_text
) m_text
->SetToolTip(tip
);
1145 if ( m_btn
) m_btn
->SetToolTip(tip
);
1149 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1150 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1153 #endif // wxUSE_TOOLTIPS
1155 // ----------------------------------------------------------------------------
1157 // ----------------------------------------------------------------------------
1159 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1160 // prepare combo box background on area in a way typical on platform
1161 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1163 wxSize sz
= GetClientSize();
1165 bool isFocused
; // also selected
1167 // For smaller size control (and for disabled background) use less spacing
1171 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1174 isEnabled
= IsEnabled();
1175 isFocused
= ShouldDrawFocus();
1177 // Windows-style: for smaller size control (and for disabled background) use less spacing
1178 focusSpacingX
= isEnabled
? 2 : 1;
1179 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1183 // Drawing a list item
1184 isEnabled
= true; // they are never disabled
1185 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1191 // Set the background sub-rectangle for selection, disabled etc
1192 wxRect
selRect(rect
);
1193 selRect
.y
+= focusSpacingY
;
1194 selRect
.height
-= (focusSpacingY
*2);
1198 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1199 wcp
+= m_widthCustomPaint
;
1201 selRect
.x
+= wcp
+ focusSpacingX
;
1202 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1208 // If popup is hidden and this control is focused,
1209 // then draw the focus-indicator (selbgcolor background etc.).
1212 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1213 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1217 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1218 bgCol
= GetBackgroundColour();
1223 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1224 bgCol
= GetBackgroundColour();
1227 dc
.SetBrush( bgCol
);
1229 dc
.DrawRectangle( selRect
);
1231 // Don't clip exactly to the selection rectangle so we can draw
1232 // to the non-selected area in front of it.
1233 wxRect
clipRect(rect
.x
,rect
.y
,
1234 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1235 dc
.SetClippingRegion(clipRect
);
1238 // Save the library size a bit for platforms that re-implement this.
1239 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1244 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, bool paintBg
)
1246 int drawState
= m_btnState
;
1249 if ( GetPopupWindowState() >= Animating
)
1250 drawState
|= wxCONTROL_PRESSED
;
1253 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1254 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1258 // Make sure area is not larger than the control
1259 if ( drawRect
.y
< rect
.y
)
1260 drawRect
.y
= rect
.y
;
1261 if ( drawRect
.height
> rect
.height
)
1262 drawRect
.height
= rect
.height
;
1264 bool enabled
= IsEnabled();
1267 drawState
|= wxCONTROL_DISABLED
;
1269 if ( !m_bmpNormal
.Ok() )
1271 // Need to clear button background even if m_btn is present
1276 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1277 bgCol
= GetParent()->GetBackgroundColour();
1279 bgCol
= GetBackgroundColour();
1283 dc
.DrawRectangle(rect
);
1286 // Draw standard button
1287 wxRendererNative::Get().DrawComboBoxDropButton(this,
1299 pBmp
= &m_bmpDisabled
;
1300 else if ( m_btnState
& wxCONTROL_PRESSED
)
1301 pBmp
= &m_bmpPressed
;
1302 else if ( m_btnState
& wxCONTROL_CURRENT
)
1305 pBmp
= &m_bmpNormal
;
1307 if ( m_blankButtonBg
)
1309 // If using blank button background, we need to clear its background
1310 // with button face colour instead of colour for rest of the control.
1313 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1314 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1317 dc
.DrawRectangle(rect
);
1320 wxRendererNative::Get().DrawPushButton(this,
1329 // Need to clear button background even if m_btn is present
1330 // (assume non-button background was cleared just before this call so brushes are good)
1332 dc
.DrawRectangle(rect
);
1335 // Draw bitmap centered in drawRect
1336 dc
.DrawBitmap(*pBmp
,
1337 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1338 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1343 void wxComboCtrlBase::RecalcAndRefresh()
1347 wxSizeEvent
evt(GetSize(),GetId());
1348 GetEventHandler()->ProcessEvent(evt
);
1353 // ----------------------------------------------------------------------------
1354 // miscellaneous event handlers
1355 // ----------------------------------------------------------------------------
1357 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1359 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1361 if ( m_ignoreEvtText
> 0 )
1368 // Change event id, object and string before relaying it forward
1369 event
.SetId(GetId());
1370 wxString s
= event
.GetString();
1371 event
.SetEventObject(this);
1376 // call if cursor is on button area or mouse is captured for the button
1377 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1380 int type
= event
.GetEventType();
1382 if ( type
== wxEVT_MOTION
)
1384 if ( flags
& wxCC_MF_ON_BUTTON
)
1386 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1388 // Mouse hover begins
1389 m_btnState
|= wxCONTROL_CURRENT
;
1390 if ( HasCapture() ) // Retain pressed state.
1391 m_btnState
|= wxCONTROL_PRESSED
;
1395 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1398 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1402 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1404 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1406 m_btnState
|= wxCONTROL_PRESSED
;
1409 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1412 // If showing popup now, do not capture mouse or there will be interference
1416 else if ( type
== wxEVT_LEFT_UP
)
1419 // Only accept event if mouse was left-press was previously accepted
1423 if ( m_btnState
& wxCONTROL_PRESSED
)
1425 // If mouse was inside, fire the click event.
1426 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1428 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1432 m_btnState
&= ~(wxCONTROL_PRESSED
);
1436 else if ( type
== wxEVT_LEAVE_WINDOW
)
1438 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1440 m_btnState
&= ~(wxCONTROL_CURRENT
);
1443 if ( IsPopupWindowState(Hidden
) )
1445 m_btnState
&= ~(wxCONTROL_PRESSED
);
1456 // returns true if event was consumed or filtered
1457 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1458 int WXUNUSED(flags
) )
1460 wxLongLong t
= ::wxGetLocalTimeMillis();
1461 int evtType
= event
.GetEventType();
1463 #if USES_WXPOPUPWINDOW || USES_WXDIALOG
1464 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1466 if ( IsPopupWindowState(Visible
) &&
1467 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1475 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1476 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1478 event
.SetEventType(0);
1485 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1487 int evtType
= event
.GetEventType();
1489 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1490 (m_windowStyle
& wxCB_READONLY
) )
1492 if ( GetPopupWindowState() >= Animating
)
1494 #if USES_WXPOPUPWINDOW
1495 // Click here always hides the popup.
1496 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1502 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1504 // In read-only mode, clicking the text is the
1505 // same as clicking the button.
1508 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1510 //if ( m_popupInterface->CycleValue() )
1512 if ( m_popupInterface
)
1513 m_popupInterface
->OnComboDoubleClick();
1518 if ( IsPopupShown() )
1520 // relay (some) mouse events to the popup
1521 if ( evtType
== wxEVT_MOUSEWHEEL
)
1522 m_popup
->AddPendingEvent(event
);
1528 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1530 if ( IsPopupShown() )
1532 // pass it to the popped up control
1533 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1537 int keycode
= event
.GetKeyCode();
1539 if ( keycode
== WXK_TAB
)
1541 wxNavigationKeyEvent evt
;
1543 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1545 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1546 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1547 : wxNavigationKeyEvent::IsBackward
));
1548 evt
.SetEventObject(mainCtrl
);
1549 evt
.SetCurrentFocus(mainCtrl
);
1550 mainCtrl
->GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1554 if ( IsKeyPopupToggle(event
) )
1560 int comboStyle
= GetWindowStyle();
1561 wxComboPopup
* popupInterface
= GetPopupControl();
1563 if ( !popupInterface
)
1569 if ( (comboStyle
& wxCB_READONLY
) ||
1570 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1572 popupInterface
->OnComboKeyEvent(event
);
1579 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1581 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1584 if ( m_text
&& m_text
!= ::wxWindow::FindFocus() )
1592 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1595 // indentation may also have changed
1596 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1597 m_absIndent
= GetNativeTextIndent();
1601 // ----------------------------------------------------------------------------
1603 // ----------------------------------------------------------------------------
1605 // Create popup window and the child control
1606 void wxComboCtrlBase::CreatePopup()
1608 wxComboPopup
* popupInterface
= m_popupInterface
;
1613 #ifdef wxComboPopupWindowBase2
1614 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
1617 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
1619 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
1620 wxPoint(-21,-21), wxSize(20, 20),
1623 m_popupWinType
= SECONDARY_POPUP_TYPE
;
1628 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1629 m_popupWinType
= PRIMARY_POPUP_TYPE
;
1631 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
1632 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
1635 popupInterface
->Create(m_winPopup
);
1636 m_popup
= popup
= popupInterface
->GetControl();
1638 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1639 popup
->PushEventHandler( m_popupExtraHandler
);
1641 // This may be helpful on some platforms
1642 // (eg. it bypasses a wxGTK popupwindow bug where
1643 // window is not initially hidden when it should be)
1646 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1649 // Destroy popup window and the child control
1650 void wxComboCtrlBase::DestroyPopup()
1655 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1657 delete m_popupExtraHandler
;
1659 delete m_popupInterface
;
1663 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
1664 delete m_popupWinEvtHandler
;
1665 m_popupWinEvtHandler
= NULL
;
1666 m_winPopup
->Destroy();
1669 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1670 m_popupInterface
= (wxComboPopup
*) NULL
;
1671 m_winPopup
= (wxWindow
*) NULL
;
1672 m_popup
= (wxWindow
*) NULL
;
1675 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1677 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1681 iface
->InitBase(this);
1684 m_popupInterface
= iface
;
1686 if ( !iface
->LazyCreate() )
1692 m_popup
= (wxWindow
*) NULL
;
1695 // This must be done after creation
1696 if ( m_valueString
.length() )
1698 iface
->SetStringValue(m_valueString
);
1703 // Ensures there is atleast the default popup
1704 void wxComboCtrlBase::EnsurePopupControl()
1706 if ( !m_popupInterface
)
1707 SetPopupControl(NULL
);
1710 void wxComboCtrlBase::OnButtonClick()
1712 // Derived classes can override this method for totally custom
1717 void wxComboCtrlBase::ShowPopup()
1719 EnsurePopupControl();
1720 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
1722 if ( IsPopupWindowState(Animating
) )
1727 // Space above and below
1733 wxSize ctrlSz
= GetSize();
1735 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1736 scrPos
= GetParent()->ClientToScreen(GetPosition());
1738 spaceAbove
= scrPos
.y
;
1739 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1741 maxHeightPopup
= spaceBelow
;
1742 if ( spaceAbove
> spaceBelow
)
1743 maxHeightPopup
= spaceAbove
;
1746 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1748 if ( widthPopup
< m_widthMinPopup
)
1749 widthPopup
= m_widthMinPopup
;
1751 wxWindow
* winPopup
= m_winPopup
;
1754 // Need to disable tab traversal of parent
1756 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1757 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1758 // that if transient popup is open, then tab traversal is to be ignored.
1759 // However, I think this code would still be needed for cases where
1760 // transient popup doesn't work yet (wxWinCE?).
1761 wxWindow
* parent
= GetParent();
1762 int parentFlags
= parent
->GetWindowStyle();
1763 if ( parentFlags
& wxTAB_TRAVERSAL
)
1765 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1766 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1772 winPopup
= m_winPopup
;
1780 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1782 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1783 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1786 popup
->SetSize(adjustedSize
);
1788 m_popupInterface
->OnPopup();
1791 // Reposition and resize popup window
1794 wxSize szp
= popup
->GetSize();
1797 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1799 // Default anchor is wxLEFT
1800 int anchorSide
= m_anchorSide
;
1802 anchorSide
= wxLEFT
;
1804 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1805 int leftX
= scrPos
.x
- m_extLeft
;
1806 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1808 // If there is not enough horizontal space, anchor on the other side.
1809 // If there is no space even then, place the popup at x 0.
1810 if ( anchorSide
== wxRIGHT
)
1814 if ( (leftX
+szp
.x
) < screenWidth
)
1815 anchorSide
= wxLEFT
;
1822 if ( (leftX
+szp
.x
) >= screenWidth
)
1825 anchorSide
= wxRIGHT
;
1831 // Select x coordinate according to the anchor side
1832 if ( anchorSide
== wxRIGHT
)
1834 else if ( anchorSide
== wxLEFT
)
1839 int showFlags
= CanDeferShow
;
1841 if ( spaceBelow
< szp
.y
)
1843 popupY
= scrPos
.y
- szp
.y
;
1844 showFlags
|= ShowAbove
;
1847 #if INSTALL_TOPLEV_HANDLER
1848 // Put top level window event handler into place
1849 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1851 if ( !m_toplevEvtHandler
)
1852 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1854 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1856 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1857 toplev
->PushEventHandler( m_toplevEvtHandler
);
1861 // Set string selection (must be this way instead of SetStringSelection)
1864 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1865 m_text
->SelectAll();
1867 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1871 // This is neede since focus/selection indication may change when popup is shown
1875 // This must be after SetStringValue
1876 m_popupWinState
= Animating
;
1878 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
1881 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
1882 AnimateShow( popupWinRect
, showFlags
) )
1884 DoShowPopup( popupWinRect
, showFlags
);
1888 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
1893 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
1895 wxWindow
* winPopup
= m_winPopup
;
1897 if ( IsPopupWindowState(Animating
) )
1899 // Make sure the popup window is shown in the right position.
1900 // Should not matter even if animation already did this.
1902 // Some platforms (GTK) may like SetSize and Move to be separate
1903 // (though the bug was probably fixed).
1904 winPopup
->SetSize( rect
);
1908 m_popupWinState
= Visible
;
1910 else if ( IsPopupWindowState(Hidden
) )
1912 // Animation was aborted
1914 wxASSERT( !winPopup
->IsShown() );
1916 m_popupWinState
= Hidden
;
1920 void wxComboCtrlBase::OnPopupDismiss()
1922 // Just in case, avoid double dismiss
1923 if ( IsPopupWindowState(Hidden
) )
1926 // NB: Focus setting is really funny, atleast on wxMSW. First of all,
1927 // we need to have SetFocus at the end. Otherwise wxTextCtrl may
1928 // freeze until focus goes somewhere else. Second, wxTreeCtrl as
1929 // popup, when dismissing, "steals" focus back to itself unless
1930 // SetFocus is called also here, exactly before m_popupWinState
1931 // is set to false. Which is truly weird since SetFocus is just
1932 // wxWindowMSW method and does not call event handler or anything like
1933 // that (ie. does not care about m_popupWinState).
1937 // This should preferably be set before focus.
1938 m_popupWinState
= Hidden
;
1940 // Inform popup control itself
1941 m_popupInterface
->OnDismiss();
1943 if ( m_popupExtraHandler
)
1944 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1946 #if INSTALL_TOPLEV_HANDLER
1947 // Remove top level window event handler
1948 if ( m_toplevEvtHandler
)
1950 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1952 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1956 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
1958 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1959 m_timeCanAcceptClick
+= 150;
1961 // If cursor not on dropdown button, then clear its state
1962 // (technically not required by all ports, but do it for all just in case)
1963 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1966 // Return parent's tab traversal flag.
1967 // See ShowPopup for notes.
1968 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
1970 wxWindow
* parent
= GetParent();
1971 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
1972 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
1975 // refresh control (necessary even if m_text)
1981 void wxComboCtrlBase::HidePopup()
1983 // Should be able to call this without popup interface
1984 if ( IsPopupWindowState(Hidden
) )
1987 // transfer value and show it in textctrl, if any
1988 if ( !IsPopupWindowState(Animating
) )
1989 SetValue( m_popupInterface
->GetStringValue() );
1996 // ----------------------------------------------------------------------------
1997 // customization methods
1998 // ----------------------------------------------------------------------------
2000 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2001 int side
, int spacingX
)
2006 m_btnSpacingX
= spacingX
;
2011 wxSize
wxComboCtrlBase::GetButtonSize()
2013 if ( m_btnSize
.x
> 0 )
2016 wxSize
retSize(m_btnWid
,m_btnHei
);
2018 // Need to call CalculateAreas now if button size is
2019 // is not explicitly specified.
2020 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2024 retSize
= m_btnSize
;
2030 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2032 const wxBitmap
& bmpPressed
,
2033 const wxBitmap
& bmpHover
,
2034 const wxBitmap
& bmpDisabled
)
2036 m_bmpNormal
= bmpNormal
;
2037 m_blankButtonBg
= blankButtonBg
;
2039 if ( bmpPressed
.Ok() )
2040 m_bmpPressed
= bmpPressed
;
2042 m_bmpPressed
= bmpNormal
;
2044 if ( bmpHover
.Ok() )
2045 m_bmpHover
= bmpHover
;
2047 m_bmpHover
= bmpNormal
;
2049 if ( bmpDisabled
.Ok() )
2050 m_bmpDisabled
= bmpDisabled
;
2052 m_bmpDisabled
= bmpNormal
;
2057 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2061 // move textctrl accordingly
2062 wxRect r
= m_text
->GetRect();
2063 int inc
= width
- m_widthCustomPaint
;
2066 m_text
->SetSize( r
);
2069 m_widthCustomPaint
= width
;
2074 void wxComboCtrlBase::SetTextIndent( int indent
)
2078 m_absIndent
= GetNativeTextIndent();
2079 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
2083 m_absIndent
= indent
;
2084 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
2090 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2092 return DEFAULT_TEXT_INDENT
;
2095 // ----------------------------------------------------------------------------
2096 // methods forwarded to wxTextCtrl
2097 // ----------------------------------------------------------------------------
2099 wxString
wxComboCtrlBase::GetValue() const
2102 return m_text
->GetValue();
2103 return m_valueString
;
2106 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
2113 m_text
->SetValue(value
);
2114 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2115 m_text
->SelectAll();
2118 m_valueString
= value
;
2122 // Since wxComboPopup may want to paint the combo as well, we need
2123 // to set the string value here (as well as sometimes in ShowPopup).
2124 if ( m_valueString
!= value
&& m_popupInterface
)
2126 m_popupInterface
->SetStringValue(value
);
2130 void wxComboCtrlBase::SetValue(const wxString
& value
)
2132 SetValueWithEvent(value
, false);
2135 // In this SetValue variant wxComboPopup::SetStringValue is not called
2136 void wxComboCtrlBase::SetText(const wxString
& value
)
2138 // Unlike in SetValue(), this must be called here or
2139 // the behaviour will no be consistent in readonlys.
2140 EnsurePopupControl();
2142 m_valueString
= value
;
2147 m_text
->SetValue( value
);
2153 void wxComboCtrlBase::Copy()
2159 void wxComboCtrlBase::Cut()
2165 void wxComboCtrlBase::Paste()
2171 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2174 m_text
->SetInsertionPoint(pos
);
2177 void wxComboCtrlBase::SetInsertionPointEnd()
2180 m_text
->SetInsertionPointEnd();
2183 long wxComboCtrlBase::GetInsertionPoint() const
2186 return m_text
->GetInsertionPoint();
2191 long wxComboCtrlBase::GetLastPosition() const
2194 return m_text
->GetLastPosition();
2199 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2202 m_text
->Replace(from
, to
, value
);
2205 void wxComboCtrlBase::Remove(long from
, long to
)
2208 m_text
->Remove(from
, to
);
2211 void wxComboCtrlBase::SetSelection(long from
, long to
)
2214 m_text
->SetSelection(from
, to
);
2217 void wxComboCtrlBase::Undo()
2223 #endif // wxUSE_COMBOCTRL