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
99 #undef DEFAULT_DROPBUTTON_WIDTH
100 #define DEFAULT_DROPBUTTON_WIDTH 22
105 // Popupwin is really only supported on wxMSW (not WINCE) and wxGTK, regardless
106 // what the wxUSE_POPUPWIN says.
107 // FIXME: Why isn't wxUSE_POPUPWIN reliable any longer? (it was in wxW2.6.2)
108 #if (!defined(__WXMSW__) && !defined(__WXGTK__)) || defined(__WXWINCE__)
109 #undef wxUSE_POPUPWIN
110 #define wxUSE_POPUPWIN 0
115 #include "wx/popupwin.h"
117 #undef USE_TRANSIENT_POPUP
118 #define USE_TRANSIENT_POPUP 0
122 // Define different types of popup windows
126 POPUPWIN_WXPOPUPTRANSIENTWINDOW
= 1,
127 POPUPWIN_WXPOPUPWINDOW
= 2,
128 POPUPWIN_WXDIALOG
= 3
132 #if USE_TRANSIENT_POPUP
133 // wxPopupTransientWindow is implemented
135 #define wxComboPopupWindowBase wxPopupTransientWindow
136 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPTRANSIENTWINDOW
137 #define USES_WXPOPUPTRANSIENTWINDOW 1
139 #if TRANSIENT_POPUPWIN_IS_PERFECT
141 #elif POPUPWIN_IS_PERFECT
142 #define wxComboPopupWindowBase2 wxPopupWindow
143 #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
144 #define USES_WXPOPUPWINDOW 1
146 #define wxComboPopupWindowBase2 wxDialog
147 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
148 #define USES_WXDIALOG 1
152 // wxPopupWindow (but not wxPopupTransientWindow) is properly implemented
154 #define wxComboPopupWindowBase wxPopupWindow
155 #define PRIMARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW
156 #define USES_WXPOPUPWINDOW 1
158 #if !POPUPWIN_IS_PERFECT
159 #define wxComboPopupWindowBase2 wxDialog
160 #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG
161 #define USES_WXDIALOG 1
165 // wxPopupWindow is not implemented
167 #define wxComboPopupWindowBase wxDialog
168 #define PRIMARY_POPUP_TYPE POPUPWIN_WXDIALOG
169 #define USES_WXDIALOG 1
174 #ifndef USES_WXPOPUPTRANSIENTWINDOW
175 #define USES_WXPOPUPTRANSIENTWINDOW 0
178 #ifndef USES_WXPOPUPWINDOW
179 #define USES_WXPOPUPWINDOW 0
182 #ifndef USES_WXDIALOG
183 #define USES_WXDIALOG 0
187 #if USES_WXPOPUPWINDOW
188 #define INSTALL_TOPLEV_HANDLER 1
190 #define INSTALL_TOPLEV_HANDLER 0
196 // * wxComboPopupWindow for external use (ie. replace old wxUniv wxPopupComboWindow)
200 // ----------------------------------------------------------------------------
201 // wxComboFrameEventHandler takes care of hiding the popup when events happen
202 // in its top level parent.
203 // ----------------------------------------------------------------------------
205 #if INSTALL_TOPLEV_HANDLER
208 // This will no longer be necessary after wxTransientPopupWindow
209 // works well on all platforms.
212 class wxComboFrameEventHandler
: public wxEvtHandler
215 wxComboFrameEventHandler( wxComboCtrlBase
* pCb
);
216 virtual ~wxComboFrameEventHandler();
220 void OnIdle( wxIdleEvent
& event
);
221 void OnMouseEvent( wxMouseEvent
& event
);
222 void OnActivate( wxActivateEvent
& event
);
223 void OnResize( wxSizeEvent
& event
);
224 void OnMove( wxMoveEvent
& event
);
225 void OnMenuEvent( wxMenuEvent
& event
);
226 void OnClose( wxCloseEvent
& event
);
229 wxWindow
* m_focusStart
;
230 wxComboCtrlBase
* m_combo
;
233 DECLARE_EVENT_TABLE()
236 BEGIN_EVENT_TABLE(wxComboFrameEventHandler
, wxEvtHandler
)
237 EVT_IDLE(wxComboFrameEventHandler::OnIdle
)
238 EVT_LEFT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
239 EVT_RIGHT_DOWN(wxComboFrameEventHandler::OnMouseEvent
)
240 EVT_SIZE(wxComboFrameEventHandler::OnResize
)
241 EVT_MOVE(wxComboFrameEventHandler::OnMove
)
242 EVT_MENU_HIGHLIGHT(wxID_ANY
,wxComboFrameEventHandler::OnMenuEvent
)
243 EVT_MENU_OPEN(wxComboFrameEventHandler::OnMenuEvent
)
244 EVT_ACTIVATE(wxComboFrameEventHandler::OnActivate
)
245 EVT_CLOSE(wxComboFrameEventHandler::OnClose
)
248 wxComboFrameEventHandler::wxComboFrameEventHandler( wxComboCtrlBase
* combo
)
254 wxComboFrameEventHandler::~wxComboFrameEventHandler()
258 void wxComboFrameEventHandler::OnPopup()
260 m_focusStart
= ::wxWindow::FindFocus();
263 void wxComboFrameEventHandler::OnIdle( wxIdleEvent
& event
)
265 wxWindow
* winFocused
= ::wxWindow::FindFocus();
267 wxWindow
* popup
= m_combo
->GetPopupControl()->GetControl();
268 wxWindow
* winpopup
= m_combo
->GetPopupWindow();
271 winFocused
!= m_focusStart
&&
272 winFocused
!= popup
&&
273 winFocused
->GetParent() != popup
&&
274 winFocused
!= winpopup
&&
275 winFocused
->GetParent() != winpopup
&&
276 winFocused
!= m_combo
&&
277 winFocused
!= m_combo
->GetButton() // GTK (atleast) requires this
280 m_combo
->HidePopup();
286 void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent
& event
)
288 m_combo
->HidePopup();
292 void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent
& event
)
294 m_combo
->HidePopup();
298 void wxComboFrameEventHandler::OnClose( wxCloseEvent
& event
)
300 m_combo
->HidePopup();
304 void wxComboFrameEventHandler::OnActivate( wxActivateEvent
& event
)
306 m_combo
->HidePopup();
310 void wxComboFrameEventHandler::OnResize( wxSizeEvent
& event
)
312 m_combo
->HidePopup();
316 void wxComboFrameEventHandler::OnMove( wxMoveEvent
& event
)
318 m_combo
->HidePopup();
322 #endif // INSTALL_TOPLEV_HANDLER
324 // ----------------------------------------------------------------------------
325 // wxComboPopupWindow is, in essence, wxPopupWindow customized for
327 // ----------------------------------------------------------------------------
329 class wxComboPopupWindow
: public wxComboPopupWindowBase
333 wxComboPopupWindow( wxComboCtrlBase
*parent
,
335 #if USES_WXPOPUPWINDOW || USES_WXPOPUPTRANSIENTWINDOW
336 : wxComboPopupWindowBase(parent
,style
)
338 : wxComboPopupWindowBase(parent
,
349 #if USES_WXPOPUPTRANSIENTWINDOW
350 virtual bool Show( bool show
);
351 virtual bool ProcessLeftDown(wxMouseEvent
& event
);
352 virtual void OnDismiss();
360 #if USES_WXPOPUPTRANSIENTWINDOW
361 bool wxComboPopupWindow::Show( bool show
)
363 // Guard against recursion
365 return wxComboPopupWindowBase::Show(show
);
369 wxASSERT( IsKindOf(CLASSINFO(wxPopupTransientWindow
)) );
371 wxPopupTransientWindow
* ptw
= (wxPopupTransientWindow
*) this;
372 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
374 if ( show
!= ptw
->IsShown() )
377 ptw
->Popup(combo
->GetPopupControl()->GetControl());
387 bool wxComboPopupWindow::ProcessLeftDown(wxMouseEvent
& event
)
389 return wxPopupTransientWindow::ProcessLeftDown(event
);
392 // First thing that happens when a transient popup closes is that this method gets called.
393 void wxComboPopupWindow::OnDismiss()
395 wxComboCtrlBase
* combo
= (wxComboCtrlBase
*) GetParent();
396 wxASSERT_MSG( combo
->IsKindOf(CLASSINFO(wxComboCtrlBase
)),
397 wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") );
399 combo
->OnPopupDismiss();
401 #endif // USES_WXPOPUPTRANSIENTWINDOW
404 // ----------------------------------------------------------------------------
405 // wxComboPopupWindowEvtHandler does bulk of the custom event handling
406 // of a popup window. It is separate so we can have different types
408 // ----------------------------------------------------------------------------
410 class wxComboPopupWindowEvtHandler
: public wxEvtHandler
414 wxComboPopupWindowEvtHandler( wxComboCtrlBase
*parent
)
419 void OnSizeEvent( wxSizeEvent
& event
);
420 void OnKeyEvent(wxKeyEvent
& event
);
422 void OnActivate( wxActivateEvent
& event
);
426 wxComboCtrlBase
* m_combo
;
428 DECLARE_EVENT_TABLE()
432 BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler
, wxEvtHandler
)
433 EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent
)
434 EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent
)
436 EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate
)
438 EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent
)
442 void wxComboPopupWindowEvtHandler::OnSizeEvent( wxSizeEvent
& WXUNUSED(event
) )
444 // Block the event so that the popup control does not get auto-resized.
447 void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent
& event
)
449 // Relay keyboard event to the main child controls
450 wxWindowList children
= m_combo
->GetPopupWindow()->GetChildren();
451 wxWindowList::iterator node
= children
.begin();
452 wxWindow
* child
= (wxWindow
*)*node
;
453 child
->AddPendingEvent(event
);
457 void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent
& event
)
459 if ( !event
.GetActive() )
461 // Tell combo control that we are dismissed.
462 m_combo
->HidePopup();
470 // ----------------------------------------------------------------------------
473 // ----------------------------------------------------------------------------
475 wxComboPopup::~wxComboPopup()
479 void wxComboPopup::OnPopup()
483 void wxComboPopup::OnDismiss()
487 wxSize
wxComboPopup::GetAdjustedSize( int minWidth
,
489 int WXUNUSED(maxHeight
) )
491 return wxSize(minWidth
,prefHeight
);
494 void wxComboPopup::DefaultPaintComboControl( wxComboCtrlBase
* combo
,
495 wxDC
& dc
, const wxRect
& rect
)
497 if ( combo
->GetWindowStyle() & wxCB_READONLY
) // ie. no textctrl
499 combo
->PrepareBackground(dc
,rect
,0);
501 dc
.DrawText( combo
->GetValue(),
502 rect
.x
+ combo
->GetTextIndent(),
503 (rect
.height
-dc
.GetCharHeight())/2 + rect
.y
);
507 void wxComboPopup::PaintComboControl( wxDC
& dc
, const wxRect
& rect
)
509 DefaultPaintComboControl(m_combo
,dc
,rect
);
512 void wxComboPopup::OnComboKeyEvent( wxKeyEvent
& event
)
517 void wxComboPopup::OnComboDoubleClick()
521 void wxComboPopup::SetStringValue( const wxString
& WXUNUSED(value
) )
525 bool wxComboPopup::LazyCreate()
530 void wxComboPopup::Dismiss()
532 m_combo
->HidePopup();
535 // ----------------------------------------------------------------------------
537 // ----------------------------------------------------------------------------
540 // This is pushed to the event handler queue of the child textctrl.
542 class wxComboBoxExtraInputHandler
: public wxEvtHandler
546 wxComboBoxExtraInputHandler( wxComboCtrlBase
* combo
)
551 virtual ~wxComboBoxExtraInputHandler() { }
552 void OnKey(wxKeyEvent
& event
);
553 void OnFocus(wxFocusEvent
& event
);
556 wxComboCtrlBase
* m_combo
;
559 DECLARE_EVENT_TABLE()
563 BEGIN_EVENT_TABLE(wxComboBoxExtraInputHandler
, wxEvtHandler
)
564 EVT_KEY_DOWN(wxComboBoxExtraInputHandler::OnKey
)
565 EVT_SET_FOCUS(wxComboBoxExtraInputHandler::OnFocus
)
569 void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent
& event
)
571 // Let the wxComboCtrl event handler have a go first.
572 wxComboCtrlBase
* combo
= m_combo
;
573 wxObject
* prevObj
= event
.GetEventObject();
575 event
.SetId(combo
->GetId());
576 event
.SetEventObject(combo
);
577 combo
->GetEventHandler()->ProcessEvent(event
);
579 event
.SetId(((wxWindow
*)prevObj
)->GetId());
580 event
.SetEventObject(prevObj
);
583 void wxComboBoxExtraInputHandler::OnFocus(wxFocusEvent
& event
)
585 // FIXME: This code does run when control is clicked,
586 // yet on Windows it doesn't select all the text.
587 if ( !(m_combo
->GetInternalFlags() & wxCC_NO_TEXT_AUTO_SELECT
) )
589 if ( m_combo
->GetTextCtrl() )
590 m_combo
->GetTextCtrl()->SelectAll();
592 m_combo
->SetSelection(-1,-1);
595 // Send focus indication to parent.
596 // NB: This is needed for cases where the textctrl gets focus
597 // instead of its parent. While this may trigger multiple
598 // wxEVT_SET_FOCUSes (since m_text->SetFocus is called
599 // from combo's focus event handler), they should be quite
601 wxFocusEvent
evt2(wxEVT_SET_FOCUS
,m_combo
->GetId());
602 evt2
.SetEventObject(m_combo
);
603 m_combo
->GetEventHandler()->ProcessEvent(evt2
);
610 // This is pushed to the event handler queue of the control in popup.
613 class wxComboPopupExtraEventHandler
: public wxEvtHandler
617 wxComboPopupExtraEventHandler( wxComboCtrlBase
* combo
)
621 m_beenInside
= false;
623 virtual ~wxComboPopupExtraEventHandler() { }
625 void OnMouseEvent( wxMouseEvent
& event
);
627 // Called from wxComboCtrlBase::OnPopupDismiss
628 void OnPopupDismiss()
630 m_beenInside
= false;
634 wxComboCtrlBase
* m_combo
;
639 DECLARE_EVENT_TABLE()
643 BEGIN_EVENT_TABLE(wxComboPopupExtraEventHandler
, wxEvtHandler
)
644 EVT_MOUSE_EVENTS(wxComboPopupExtraEventHandler::OnMouseEvent
)
648 void wxComboPopupExtraEventHandler::OnMouseEvent( wxMouseEvent
& event
)
650 wxPoint pt
= event
.GetPosition();
651 wxSize sz
= m_combo
->GetPopupControl()->GetControl()->GetClientSize();
652 int evtType
= event
.GetEventType();
653 bool isInside
= pt
.x
>= 0 && pt
.y
>= 0 && pt
.x
< sz
.x
&& pt
.y
< sz
.y
;
655 if ( evtType
== wxEVT_MOTION
||
656 evtType
== wxEVT_LEFT_DOWN
||
657 evtType
== wxEVT_RIGHT_DOWN
)
659 // Block motion and click events outside the popup
660 if ( !isInside
|| !m_combo
->IsPopupShown() )
666 else if ( evtType
== wxEVT_LEFT_UP
)
668 if ( !m_combo
->IsPopupShown() )
683 // Some mouse events to popup that happen outside it, before cursor
684 // has been inside the popu, need to be ignored by it but relayed to
687 wxWindow
* btn
= m_combo
->GetButton();
689 btn
->GetEventHandler()->AddPendingEvent(event
);
691 m_combo
->GetEventHandler()->AddPendingEvent(event
);
703 // ----------------------------------------------------------------------------
705 // ----------------------------------------------------------------------------
708 BEGIN_EVENT_TABLE(wxComboCtrlBase
, wxControl
)
709 EVT_TEXT(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
710 EVT_SIZE(wxComboCtrlBase::OnSizeEvent
)
711 EVT_SET_FOCUS(wxComboCtrlBase::OnFocusEvent
)
712 EVT_KILL_FOCUS(wxComboCtrlBase::OnFocusEvent
)
713 //EVT_BUTTON(wxID_ANY,wxComboCtrlBase::OnButtonClickEvent)
714 EVT_KEY_DOWN(wxComboCtrlBase::OnKeyEvent
)
715 EVT_TEXT_ENTER(wxID_ANY
,wxComboCtrlBase::OnTextCtrlEvent
)
716 EVT_SYS_COLOUR_CHANGED(wxComboCtrlBase::OnSysColourChanged
)
720 IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase
, wxControl
)
722 void wxComboCtrlBase::Init()
724 m_winPopup
= (wxWindow
*)NULL
;
725 m_popup
= (wxWindow
*)NULL
;
726 m_popupWinState
= Hidden
;
727 m_btn
= (wxWindow
*) NULL
;
728 m_text
= (wxTextCtrl
*) NULL
;
729 m_popupInterface
= (wxComboPopup
*) NULL
;
731 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
732 m_textEvtHandler
= (wxEvtHandler
*) NULL
;
734 #if INSTALL_TOPLEV_HANDLER
735 m_toplevEvtHandler
= (wxEvtHandler
*) NULL
;
738 m_mainCtrlWnd
= this;
741 m_widthMinPopup
= -1;
743 m_widthCustomPaint
= 0;
744 m_widthCustomBorder
= 0;
748 m_blankButtonBg
= false;
750 m_popupWinType
= POPUPWIN_NONE
;
751 m_btnWid
= m_btnHei
= -1;
759 m_timeCanAcceptClick
= 0;
762 bool wxComboCtrlBase::Create(wxWindow
*parent
,
764 const wxString
& value
,
768 const wxValidator
& validator
,
769 const wxString
& name
)
771 if ( !wxControl::Create(parent
,
775 style
| wxWANTS_CHARS
,
780 m_valueString
= value
;
784 m_absIndent
= GetNativeTextIndent();
786 m_iFlags
|= wxCC_IFLAG_CREATED
;
788 // If x and y indicate valid size, wxSizeEvent won't be
789 // emitted automatically, so we need to add artifical one.
790 if ( size
.x
> 0 && size
.y
> 0 )
792 wxSizeEvent
evt(size
,GetId());
793 GetEventHandler()->AddPendingEvent(evt
);
799 void wxComboCtrlBase::InstallInputHandlers()
803 m_textEvtHandler
= new wxComboBoxExtraInputHandler(this);
804 m_text
->PushEventHandler(m_textEvtHandler
);
809 wxComboCtrlBase::CreateTextCtrl(int style
, const wxValidator
& validator
)
811 if ( !(m_windowStyle
& wxCB_READONLY
) )
816 // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is
817 // not used by the wxPropertyGrid and therefore the tab is processed by
818 // looking at ancestors to see if they have wxTAB_TRAVERSAL. The
819 // navigation event is then sent to the wrong window.
820 style
|= wxTE_PROCESS_TAB
;
822 if ( HasFlag(wxTE_PROCESS_ENTER
) )
823 style
|= wxTE_PROCESS_ENTER
;
825 // Ignore EVT_TEXT generated by the constructor (but only
826 // if the event redirector already exists)
827 // NB: This must be " = 1" instead of "++";
828 if ( m_textEvtHandler
)
833 m_text
= new wxTextCtrl(this, wxID_ANY
, m_valueString
,
834 wxDefaultPosition
, wxSize(10,-1),
839 void wxComboCtrlBase::OnThemeChange()
841 SetOwnBackgroundColour(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
1076 // these are the numbers from the HIG:
1077 switch ( m_windowVariant
)
1079 case wxWINDOW_VARIANT_NORMAL
:
1083 case wxWINDOW_VARIANT_SMALL
:
1086 case wxWINDOW_VARIANT_MINI
:
1092 wxSize
ret(sizeText
.x
+ COMBO_MARGIN
+ DEFAULT_DROPBUTTON_WIDTH
,
1099 void wxComboCtrlBase::OnSizeEvent( wxSizeEvent
& event
)
1104 // defined by actual wxComboCtrls
1110 // ----------------------------------------------------------------------------
1111 // standard operations
1112 // ----------------------------------------------------------------------------
1114 bool wxComboCtrlBase::Enable(bool enable
)
1116 if ( !wxControl::Enable(enable
) )
1120 m_btn
->Enable(enable
);
1122 m_text
->Enable(enable
);
1127 bool wxComboCtrlBase::Show(bool show
)
1129 if ( !wxControl::Show(show
) )
1141 bool wxComboCtrlBase::SetFont ( const wxFont
& font
)
1143 if ( !wxControl::SetFont(font
) )
1147 m_text
->SetFont(font
);
1153 void wxComboCtrlBase::DoSetToolTip(wxToolTip
*tooltip
)
1155 wxControl::DoSetToolTip(tooltip
);
1157 // Set tool tip for button and text box
1160 const wxString
&tip
= tooltip
->GetTip();
1161 if ( m_text
) m_text
->SetToolTip(tip
);
1162 if ( m_btn
) m_btn
->SetToolTip(tip
);
1166 if ( m_text
) m_text
->SetToolTip( (wxToolTip
*) NULL
);
1167 if ( m_btn
) m_btn
->SetToolTip( (wxToolTip
*) NULL
);
1170 #endif // wxUSE_TOOLTIPS
1172 #if wxUSE_VALIDATORS
1173 void wxComboCtrlBase::SetValidator(const wxValidator
& validator
)
1175 wxTextCtrl
* textCtrl
= GetTextCtrl();
1178 textCtrl
->SetValidator( validator
);
1181 wxValidator
* wxComboCtrlBase::GetValidator()
1183 wxTextCtrl
* textCtrl
= GetTextCtrl();
1186 return textCtrl
->GetValidator();
1188 return wxControl::GetValidator();
1190 #endif // wxUSE_VALIDATORS
1192 // ----------------------------------------------------------------------------
1194 // ----------------------------------------------------------------------------
1196 #if (!defined(__WXMSW__)) || defined(__WXUNIVERSAL__)
1197 // prepare combo box background on area in a way typical on platform
1198 void wxComboCtrlBase::PrepareBackground( wxDC
& dc
, const wxRect
& rect
, int flags
) const
1200 wxSize sz
= GetClientSize();
1202 bool isFocused
; // also selected
1204 // For smaller size control (and for disabled background) use less spacing
1208 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1211 isEnabled
= IsEnabled();
1212 isFocused
= ShouldDrawFocus();
1214 // Windows-style: for smaller size control (and for disabled background) use less spacing
1215 focusSpacingX
= isEnabled
? 2 : 1;
1216 focusSpacingY
= sz
.y
> (GetCharHeight()+2) && isEnabled
? 2 : 1;
1220 // Drawing a list item
1221 isEnabled
= true; // they are never disabled
1222 isFocused
= flags
& wxCONTROL_SELECTED
? true : false;
1228 // Set the background sub-rectangle for selection, disabled etc
1229 wxRect
selRect(rect
);
1230 selRect
.y
+= focusSpacingY
;
1231 selRect
.height
-= (focusSpacingY
*2);
1235 if ( !(flags
& wxCONTROL_ISSUBMENU
) )
1236 wcp
+= m_widthCustomPaint
;
1238 selRect
.x
+= wcp
+ focusSpacingX
;
1239 selRect
.width
-= wcp
+ (focusSpacingX
*2);
1245 // If popup is hidden and this control is focused,
1246 // then draw the focus-indicator (selbgcolor background etc.).
1249 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT
) );
1250 bgCol
= wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
);
1254 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
) );
1255 bgCol
= GetBackgroundColour();
1260 dc
.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT
) );
1261 bgCol
= GetBackgroundColour();
1264 dc
.SetBrush( bgCol
);
1266 dc
.DrawRectangle( selRect
);
1268 // Don't clip exactly to the selection rectangle so we can draw
1269 // to the non-selected area in front of it.
1270 wxRect
clipRect(rect
.x
,rect
.y
,
1271 (selRect
.x
+selRect
.width
)-rect
.x
,rect
.height
);
1272 dc
.SetClippingRegion(clipRect
);
1275 // Save the library size a bit for platforms that re-implement this.
1276 void wxComboCtrlBase::PrepareBackground( wxDC
&, const wxRect
&, int ) const
1281 void wxComboCtrlBase::DrawButton( wxDC
& dc
, const wxRect
& rect
, int paintBg
)
1283 int drawState
= m_btnState
;
1286 if ( GetPopupWindowState() >= Animating
)
1287 drawState
|= wxCONTROL_PRESSED
;
1290 wxRect
drawRect(rect
.x
+m_btnSpacingX
,
1291 rect
.y
+((rect
.height
-m_btnSize
.y
)/2),
1295 // Make sure area is not larger than the control
1296 if ( drawRect
.y
< rect
.y
)
1297 drawRect
.y
= rect
.y
;
1298 if ( drawRect
.height
> rect
.height
)
1299 drawRect
.height
= rect
.height
;
1301 bool enabled
= IsEnabled();
1304 drawState
|= wxCONTROL_DISABLED
;
1306 if ( !m_bmpNormal
.Ok() )
1308 // Need to clear button background even if m_btn is present
1313 if ( m_iFlags
& wxCC_IFLAG_BUTTON_OUTSIDE
)
1314 bgCol
= GetParent()->GetBackgroundColour();
1316 bgCol
= GetBackgroundColour();
1320 dc
.DrawRectangle(rect
);
1323 // Draw standard button
1324 wxRendererNative::Get().DrawComboBoxDropButton(this,
1336 pBmp
= &m_bmpDisabled
;
1337 else if ( m_btnState
& wxCONTROL_PRESSED
)
1338 pBmp
= &m_bmpPressed
;
1339 else if ( m_btnState
& wxCONTROL_CURRENT
)
1342 pBmp
= &m_bmpNormal
;
1344 if ( m_blankButtonBg
)
1346 // If using blank button background, we need to clear its background
1347 // with button face colour instead of colour for rest of the control.
1350 wxColour bgCol
= GetParent()->GetBackgroundColour(); //wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
1351 //wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
1354 dc
.DrawRectangle(rect
);
1357 wxRendererNative::Get().DrawPushButton(this,
1366 // Need to clear button background even if m_btn is present
1367 // (assume non-button background was cleared just before this call so brushes are good)
1369 dc
.DrawRectangle(rect
);
1372 // Draw bitmap centered in drawRect
1373 dc
.DrawBitmap(*pBmp
,
1374 drawRect
.x
+ (drawRect
.width
-pBmp
->GetWidth())/2,
1375 drawRect
.y
+ (drawRect
.height
-pBmp
->GetHeight())/2,
1380 void wxComboCtrlBase::RecalcAndRefresh()
1384 wxSizeEvent
evt(GetSize(),GetId());
1385 GetEventHandler()->ProcessEvent(evt
);
1390 // ----------------------------------------------------------------------------
1391 // miscellaneous event handlers
1392 // ----------------------------------------------------------------------------
1394 void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent
& event
)
1396 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
1398 if ( m_ignoreEvtText
> 0 )
1405 // Change event id, object and string before relaying it forward
1406 event
.SetId(GetId());
1407 wxString s
= event
.GetString();
1408 event
.SetEventObject(this);
1413 // call if cursor is on button area or mouse is captured for the button
1414 bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent
& event
,
1417 int type
= event
.GetEventType();
1419 if ( type
== wxEVT_MOTION
)
1421 if ( flags
& wxCC_MF_ON_BUTTON
)
1423 if ( !(m_btnState
& wxCONTROL_CURRENT
) )
1425 // Mouse hover begins
1426 m_btnState
|= wxCONTROL_CURRENT
;
1427 if ( HasCapture() ) // Retain pressed state.
1428 m_btnState
|= wxCONTROL_PRESSED
;
1432 else if ( (m_btnState
& wxCONTROL_CURRENT
) )
1435 m_btnState
&= ~(wxCONTROL_CURRENT
|wxCONTROL_PRESSED
);
1439 else if ( type
== wxEVT_LEFT_DOWN
|| type
== wxEVT_LEFT_DCLICK
)
1441 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1443 m_btnState
|= wxCONTROL_PRESSED
;
1446 if ( !(m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
) )
1449 // If showing popup now, do not capture mouse or there will be interference
1453 else if ( type
== wxEVT_LEFT_UP
)
1456 // Only accept event if mouse was left-press was previously accepted
1460 if ( m_btnState
& wxCONTROL_PRESSED
)
1462 // If mouse was inside, fire the click event.
1463 if ( m_iFlags
& wxCC_POPUP_ON_MOUSE_UP
)
1465 if ( flags
& (wxCC_MF_ON_CLICK_AREA
|wxCC_MF_ON_BUTTON
) )
1469 m_btnState
&= ~(wxCONTROL_PRESSED
);
1473 else if ( type
== wxEVT_LEAVE_WINDOW
)
1475 if ( m_btnState
& (wxCONTROL_CURRENT
|wxCONTROL_PRESSED
) )
1477 m_btnState
&= ~(wxCONTROL_CURRENT
);
1480 if ( IsPopupWindowState(Hidden
) )
1482 m_btnState
&= ~(wxCONTROL_PRESSED
);
1493 // returns true if event was consumed or filtered
1494 bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent
& event
,
1495 int WXUNUSED(flags
) )
1497 wxLongLong t
= ::wxGetLocalTimeMillis();
1498 int evtType
= event
.GetEventType();
1500 #if USES_WXPOPUPWINDOW || USES_WXDIALOG
1501 if ( m_popupWinType
!= POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1503 if ( IsPopupWindowState(Visible
) &&
1504 ( evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_RIGHT_DOWN
) )
1512 // Filter out clicks on button immediately after popup dismiss (Windows like behaviour)
1513 if ( evtType
== wxEVT_LEFT_DOWN
&& t
< m_timeCanAcceptClick
)
1515 event
.SetEventType(0);
1522 void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent
& event
)
1524 int evtType
= event
.GetEventType();
1526 if ( (evtType
== wxEVT_LEFT_DOWN
|| evtType
== wxEVT_LEFT_DCLICK
) &&
1527 (m_windowStyle
& wxCB_READONLY
) )
1529 if ( GetPopupWindowState() >= Animating
)
1531 #if USES_WXPOPUPWINDOW
1532 // Click here always hides the popup.
1533 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1539 if ( !(m_windowStyle
& wxCC_SPECIAL_DCLICK
) )
1541 // In read-only mode, clicking the text is the
1542 // same as clicking the button.
1545 else if ( /*evtType == wxEVT_LEFT_UP || */evtType
== wxEVT_LEFT_DCLICK
)
1547 //if ( m_popupInterface->CycleValue() )
1549 if ( m_popupInterface
)
1550 m_popupInterface
->OnComboDoubleClick();
1555 if ( IsPopupShown() )
1557 // relay (some) mouse events to the popup
1558 if ( evtType
== wxEVT_MOUSEWHEEL
)
1559 m_popup
->AddPendingEvent(event
);
1565 void wxComboCtrlBase::OnKeyEvent(wxKeyEvent
& event
)
1567 if ( IsPopupShown() )
1569 // pass it to the popped up control
1570 GetPopupControl()->GetControl()->AddPendingEvent(event
);
1574 int keycode
= event
.GetKeyCode();
1576 if ( keycode
== WXK_TAB
)
1578 wxNavigationKeyEvent evt
;
1580 wxWindow
* mainCtrl
= GetMainWindowOfCompositeControl();
1582 evt
.SetFlags(wxNavigationKeyEvent::FromTab
|
1583 (!event
.ShiftDown() ? wxNavigationKeyEvent::IsForward
1584 : wxNavigationKeyEvent::IsBackward
));
1585 evt
.SetEventObject(mainCtrl
);
1586 evt
.SetCurrentFocus(mainCtrl
);
1587 mainCtrl
->GetParent()->GetEventHandler()->AddPendingEvent(evt
);
1591 if ( IsKeyPopupToggle(event
) )
1597 int comboStyle
= GetWindowStyle();
1598 wxComboPopup
* popupInterface
= GetPopupControl();
1600 if ( !popupInterface
)
1606 if ( (comboStyle
& wxCB_READONLY
) ||
1607 (keycode
!= WXK_RIGHT
&& keycode
!= WXK_LEFT
) )
1609 popupInterface
->OnComboKeyEvent(event
);
1616 void wxComboCtrlBase::OnFocusEvent( wxFocusEvent
& event
)
1618 if ( event
.GetEventType() == wxEVT_SET_FOCUS
)
1621 wxWindow
* tc
= GetTextCtrl();
1622 if ( tc
&& tc
!= DoFindFocus() )
1630 void wxComboCtrlBase::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
1633 // indentation may also have changed
1634 if ( !(m_iFlags
& wxCC_IFLAG_INDENT_SET
) )
1635 m_absIndent
= GetNativeTextIndent();
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1643 // Create popup window and the child control
1644 void wxComboCtrlBase::CreatePopup()
1646 wxComboPopup
* popupInterface
= m_popupInterface
;
1651 #ifdef wxComboPopupWindowBase2
1652 if ( m_iFlags
& wxCC_IFLAG_USE_ALT_POPUP
)
1655 m_winPopup
= new wxComboPopupWindowBase2( this, wxNO_BORDER
);
1657 m_winPopup
= new wxComboPopupWindowBase2( this, wxID_ANY
, wxEmptyString
,
1658 wxPoint(-21,-21), wxSize(20, 20),
1661 m_popupWinType
= SECONDARY_POPUP_TYPE
;
1666 m_winPopup
= new wxComboPopupWindow( this, wxNO_BORDER
);
1667 m_popupWinType
= PRIMARY_POPUP_TYPE
;
1669 m_popupWinEvtHandler
= new wxComboPopupWindowEvtHandler(this);
1670 m_winPopup
->PushEventHandler(m_popupWinEvtHandler
);
1673 popupInterface
->Create(m_winPopup
);
1674 m_popup
= popup
= popupInterface
->GetControl();
1676 m_popupExtraHandler
= new wxComboPopupExtraEventHandler(this);
1677 popup
->PushEventHandler( m_popupExtraHandler
);
1679 // This may be helpful on some platforms
1680 // (eg. it bypasses a wxGTK popupwindow bug where
1681 // window is not initially hidden when it should be)
1684 popupInterface
->m_iFlags
|= wxCP_IFLAG_CREATED
;
1687 // Destroy popup window and the child control
1688 void wxComboCtrlBase::DestroyPopup()
1693 m_popup
->RemoveEventHandler(m_popupExtraHandler
);
1695 delete m_popupExtraHandler
;
1697 delete m_popupInterface
;
1701 m_winPopup
->RemoveEventHandler(m_popupWinEvtHandler
);
1702 delete m_popupWinEvtHandler
;
1703 m_popupWinEvtHandler
= NULL
;
1704 m_winPopup
->Destroy();
1707 m_popupExtraHandler
= (wxEvtHandler
*) NULL
;
1708 m_popupInterface
= (wxComboPopup
*) NULL
;
1709 m_winPopup
= (wxWindow
*) NULL
;
1710 m_popup
= (wxWindow
*) NULL
;
1713 void wxComboCtrlBase::DoSetPopupControl(wxComboPopup
* iface
)
1715 wxCHECK_RET( iface
, wxT("no popup interface set for wxComboCtrl") );
1719 iface
->InitBase(this);
1722 m_popupInterface
= iface
;
1724 if ( !iface
->LazyCreate() )
1730 m_popup
= (wxWindow
*) NULL
;
1733 // This must be done after creation
1734 if ( m_valueString
.length() )
1736 iface
->SetStringValue(m_valueString
);
1741 // Ensures there is atleast the default popup
1742 void wxComboCtrlBase::EnsurePopupControl()
1744 if ( !m_popupInterface
)
1745 SetPopupControl(NULL
);
1748 void wxComboCtrlBase::OnButtonClick()
1750 // Derived classes can override this method for totally custom
1755 void wxComboCtrlBase::ShowPopup()
1757 EnsurePopupControl();
1758 wxCHECK_RET( !IsPopupWindowState(Visible
), wxT("popup window already shown") );
1760 if ( IsPopupWindowState(Animating
) )
1765 // Space above and below
1771 wxSize ctrlSz
= GetSize();
1773 screenHeight
= wxSystemSettings::GetMetric( wxSYS_SCREEN_Y
);
1774 scrPos
= GetParent()->ClientToScreen(GetPosition());
1776 spaceAbove
= scrPos
.y
;
1777 spaceBelow
= screenHeight
- spaceAbove
- ctrlSz
.y
;
1779 maxHeightPopup
= spaceBelow
;
1780 if ( spaceAbove
> spaceBelow
)
1781 maxHeightPopup
= spaceAbove
;
1784 int widthPopup
= ctrlSz
.x
+ m_extLeft
+ m_extRight
;
1786 if ( widthPopup
< m_widthMinPopup
)
1787 widthPopup
= m_widthMinPopup
;
1789 wxWindow
* winPopup
= m_winPopup
;
1792 // Need to disable tab traversal of parent
1794 // NB: This is to fix a bug in wxMSW. In theory it could also be fixed
1795 // by, for instance, adding check to window.cpp:wxWindowMSW::MSWProcessMessage
1796 // that if transient popup is open, then tab traversal is to be ignored.
1797 // However, I think this code would still be needed for cases where
1798 // transient popup doesn't work yet (wxWinCE?).
1799 wxWindow
* parent
= GetParent();
1800 int parentFlags
= parent
->GetWindowStyle();
1801 if ( parentFlags
& wxTAB_TRAVERSAL
)
1803 parent
->SetWindowStyle( parentFlags
& ~(wxTAB_TRAVERSAL
) );
1804 m_iFlags
|= wxCC_IFLAG_PARENT_TAB_TRAVERSAL
;
1810 winPopup
= m_winPopup
;
1820 wxASSERT( !m_popup
|| m_popup
== popup
); // Consistency check.
1822 wxSize adjustedSize
= m_popupInterface
->GetAdjustedSize(widthPopup
,
1823 m_heightPopup
<=0?DEFAULT_POPUP_HEIGHT
:m_heightPopup
,
1826 popup
->SetSize(adjustedSize
);
1828 m_popupInterface
->OnPopup();
1831 // Reposition and resize popup window
1834 wxSize szp
= popup
->GetSize();
1837 int popupY
= scrPos
.y
+ ctrlSz
.y
;
1839 // Default anchor is wxLEFT
1840 int anchorSide
= m_anchorSide
;
1842 anchorSide
= wxLEFT
;
1844 int rightX
= scrPos
.x
+ ctrlSz
.x
+ m_extRight
- szp
.x
;
1845 int leftX
= scrPos
.x
- m_extLeft
;
1846 int screenWidth
= wxSystemSettings::GetMetric( wxSYS_SCREEN_X
);
1848 // If there is not enough horizontal space, anchor on the other side.
1849 // If there is no space even then, place the popup at x 0.
1850 if ( anchorSide
== wxRIGHT
)
1854 if ( (leftX
+szp
.x
) < screenWidth
)
1855 anchorSide
= wxLEFT
;
1862 if ( (leftX
+szp
.x
) >= screenWidth
)
1865 anchorSide
= wxRIGHT
;
1871 // Select x coordinate according to the anchor side
1872 if ( anchorSide
== wxRIGHT
)
1874 else if ( anchorSide
== wxLEFT
)
1879 int showFlags
= CanDeferShow
;
1881 if ( spaceBelow
< szp
.y
)
1883 popupY
= scrPos
.y
- szp
.y
;
1884 showFlags
|= ShowAbove
;
1887 #if INSTALL_TOPLEV_HANDLER
1888 // Put top level window event handler into place
1889 if ( m_popupWinType
== POPUPWIN_WXPOPUPWINDOW
)
1891 if ( !m_toplevEvtHandler
)
1892 m_toplevEvtHandler
= new wxComboFrameEventHandler(this);
1894 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1896 ((wxComboFrameEventHandler
*)m_toplevEvtHandler
)->OnPopup();
1897 toplev
->PushEventHandler( m_toplevEvtHandler
);
1901 // Set string selection (must be this way instead of SetStringSelection)
1904 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
1905 m_text
->SelectAll();
1907 m_popupInterface
->SetStringValue( m_text
->GetValue() );
1911 // This is neede since focus/selection indication may change when popup is shown
1915 // This must be after SetStringValue
1916 m_popupWinState
= Animating
;
1918 wxRect
popupWinRect( popupX
, popupY
, szp
.x
, szp
.y
);
1921 if ( (m_iFlags
& wxCC_IFLAG_DISABLE_POPUP_ANIM
) ||
1922 AnimateShow( popupWinRect
, showFlags
) )
1924 DoShowPopup( popupWinRect
, showFlags
);
1928 bool wxComboCtrlBase::AnimateShow( const wxRect
& WXUNUSED(rect
), int WXUNUSED(flags
) )
1933 void wxComboCtrlBase::DoShowPopup( const wxRect
& rect
, int WXUNUSED(flags
) )
1935 wxWindow
* winPopup
= m_winPopup
;
1937 if ( IsPopupWindowState(Animating
) )
1939 // Make sure the popup window is shown in the right position.
1940 // Should not matter even if animation already did this.
1942 // Some platforms (GTK) may like SetSize and Move to be separate
1943 // (though the bug was probably fixed).
1944 winPopup
->SetSize( rect
);
1948 m_popupWinState
= Visible
;
1950 else if ( IsPopupWindowState(Hidden
) )
1952 // Animation was aborted
1954 wxASSERT( !winPopup
->IsShown() );
1956 m_popupWinState
= Hidden
;
1960 void wxComboCtrlBase::OnPopupDismiss()
1962 // Just in case, avoid double dismiss
1963 if ( IsPopupWindowState(Hidden
) )
1966 // This must be set before focus - otherwise there will be recursive
1967 // OnPopupDismisses.
1968 m_popupWinState
= Hidden
;
1971 m_winPopup
->Disable();
1973 // Inform popup control itself
1974 m_popupInterface
->OnDismiss();
1976 if ( m_popupExtraHandler
)
1977 ((wxComboPopupExtraEventHandler
*)m_popupExtraHandler
)->OnPopupDismiss();
1979 #if INSTALL_TOPLEV_HANDLER
1980 // Remove top level window event handler
1981 if ( m_toplevEvtHandler
)
1983 wxWindow
* toplev
= ::wxGetTopLevelParent( this );
1985 toplev
->RemoveEventHandler( m_toplevEvtHandler
);
1989 m_timeCanAcceptClick
= ::wxGetLocalTimeMillis();
1991 if ( m_popupWinType
== POPUPWIN_WXPOPUPTRANSIENTWINDOW
)
1992 m_timeCanAcceptClick
+= 150;
1994 // If cursor not on dropdown button, then clear its state
1995 // (technically not required by all ports, but do it for all just in case)
1996 if ( !m_btnArea
.Contains(ScreenToClient(::wxGetMousePosition())) )
1999 // Return parent's tab traversal flag.
2000 // See ShowPopup for notes.
2001 if ( m_iFlags
& wxCC_IFLAG_PARENT_TAB_TRAVERSAL
)
2003 wxWindow
* parent
= GetParent();
2004 parent
->SetWindowStyle( parent
->GetWindowStyle() | wxTAB_TRAVERSAL
);
2005 m_iFlags
&= ~(wxCC_IFLAG_PARENT_TAB_TRAVERSAL
);
2008 // refresh control (necessary even if m_text)
2014 void wxComboCtrlBase::HidePopup()
2016 // Should be able to call this without popup interface
2017 if ( IsPopupWindowState(Hidden
) )
2020 // transfer value and show it in textctrl, if any
2021 if ( !IsPopupWindowState(Animating
) )
2022 SetValue( m_popupInterface
->GetStringValue() );
2029 // ----------------------------------------------------------------------------
2030 // customization methods
2031 // ----------------------------------------------------------------------------
2033 void wxComboCtrlBase::SetButtonPosition( int width
, int height
,
2034 int side
, int spacingX
)
2039 m_btnSpacingX
= spacingX
;
2044 wxSize
wxComboCtrlBase::GetButtonSize()
2046 if ( m_btnSize
.x
> 0 )
2049 wxSize
retSize(m_btnWid
,m_btnHei
);
2051 // Need to call CalculateAreas now if button size is
2052 // is not explicitly specified.
2053 if ( retSize
.x
<= 0 || retSize
.y
<= 0)
2057 retSize
= m_btnSize
;
2063 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap
& bmpNormal
,
2065 const wxBitmap
& bmpPressed
,
2066 const wxBitmap
& bmpHover
,
2067 const wxBitmap
& bmpDisabled
)
2069 m_bmpNormal
= bmpNormal
;
2070 m_blankButtonBg
= blankButtonBg
;
2072 if ( bmpPressed
.Ok() )
2073 m_bmpPressed
= bmpPressed
;
2075 m_bmpPressed
= bmpNormal
;
2077 if ( bmpHover
.Ok() )
2078 m_bmpHover
= bmpHover
;
2080 m_bmpHover
= bmpNormal
;
2082 if ( bmpDisabled
.Ok() )
2083 m_bmpDisabled
= bmpDisabled
;
2085 m_bmpDisabled
= bmpNormal
;
2090 void wxComboCtrlBase::SetCustomPaintWidth( int width
)
2094 // move textctrl accordingly
2095 wxRect r
= m_text
->GetRect();
2096 int inc
= width
- m_widthCustomPaint
;
2099 m_text
->SetSize( r
);
2102 m_widthCustomPaint
= width
;
2107 void wxComboCtrlBase::SetTextIndent( int indent
)
2111 m_absIndent
= GetNativeTextIndent();
2112 m_iFlags
&= ~(wxCC_IFLAG_INDENT_SET
);
2116 m_absIndent
= indent
;
2117 m_iFlags
|= wxCC_IFLAG_INDENT_SET
;
2123 wxCoord
wxComboCtrlBase::GetNativeTextIndent() const
2125 return DEFAULT_TEXT_INDENT
;
2128 // ----------------------------------------------------------------------------
2129 // methods forwarded to wxTextCtrl
2130 // ----------------------------------------------------------------------------
2132 wxString
wxComboCtrlBase::GetValue() const
2135 return m_text
->GetValue();
2136 return m_valueString
;
2139 void wxComboCtrlBase::SetValueWithEvent(const wxString
& value
, bool withEvent
)
2146 m_text
->SetValue(value
);
2147 if ( !(m_iFlags
& wxCC_NO_TEXT_AUTO_SELECT
) )
2148 m_text
->SelectAll();
2151 m_valueString
= value
;
2155 // Since wxComboPopup may want to paint the combo as well, we need
2156 // to set the string value here (as well as sometimes in ShowPopup).
2157 if ( m_valueString
!= value
&& m_popupInterface
)
2159 m_popupInterface
->SetStringValue(value
);
2163 void wxComboCtrlBase::SetValue(const wxString
& value
)
2165 SetValueWithEvent(value
, false);
2168 // In this SetValue variant wxComboPopup::SetStringValue is not called
2169 void wxComboCtrlBase::SetText(const wxString
& value
)
2171 // Unlike in SetValue(), this must be called here or
2172 // the behaviour will no be consistent in readonlys.
2173 EnsurePopupControl();
2175 m_valueString
= value
;
2180 m_text
->SetValue( value
);
2186 void wxComboCtrlBase::Copy()
2192 void wxComboCtrlBase::Cut()
2198 void wxComboCtrlBase::Paste()
2204 void wxComboCtrlBase::SetInsertionPoint(long pos
)
2207 m_text
->SetInsertionPoint(pos
);
2210 void wxComboCtrlBase::SetInsertionPointEnd()
2213 m_text
->SetInsertionPointEnd();
2216 long wxComboCtrlBase::GetInsertionPoint() const
2219 return m_text
->GetInsertionPoint();
2224 long wxComboCtrlBase::GetLastPosition() const
2227 return m_text
->GetLastPosition();
2232 void wxComboCtrlBase::Replace(long from
, long to
, const wxString
& value
)
2235 m_text
->Replace(from
, to
, value
);
2238 void wxComboCtrlBase::Remove(long from
, long to
)
2241 m_text
->Remove(from
, to
);
2244 void wxComboCtrlBase::SetSelection(long from
, long to
)
2247 m_text
->SetSelection(from
, to
);
2250 void wxComboCtrlBase::Undo()
2256 #endif // wxUSE_COMBOCTRL