X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/22a35096a0a9c3fe4d3d32b8d68a361126ef9677..cd7d36c065d638f48cff0845a43e35b9ed1e25f6:/src/common/combocmn.cpp diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index cb1ae22dfc..aef6c75cbf 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -35,7 +35,6 @@ #include "wx/timer.h" #endif -#include "wx/dcbuffer.h" #include "wx/tooltip.h" #include "wx/combo.h" @@ -53,7 +52,7 @@ #define BMP_BUTTON_MARGIN 4 -#define DEFAULT_POPUP_HEIGHT 200 +#define DEFAULT_POPUP_HEIGHT 400 #define DEFAULT_TEXT_INDENT 3 @@ -63,6 +62,7 @@ #if defined(__WXMSW__) #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) +#define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered //#undef wxUSE_POPUPWIN //#define wxUSE_POPUPWIN 0 @@ -70,14 +70,17 @@ #elif defined(__WXGTK__) #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) +#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered #elif defined(__WXMAC__) #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform) +#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered #else #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform) +#define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered #endif @@ -610,9 +613,6 @@ END_EVENT_TABLE() IMPLEMENT_ABSTRACT_CLASS(wxComboCtrlBase, wxControl) -// Have global double buffer - should be enough for multiple combos -static wxBitmap* gs_doubleBuffer = (wxBitmap*) NULL; - void wxComboCtrlBase::Init() { m_winPopup = (wxWindow *)NULL; @@ -638,6 +638,7 @@ void wxComboCtrlBase::Init() m_btnState = 0; m_btnWidDefault = 0; m_blankButtonBg = false; + m_ignoreEvtText = 0; m_btnWid = m_btnHei = -1; m_btnSide = wxRIGHT; m_btnSpacingX = 0; @@ -646,7 +647,6 @@ void wxComboCtrlBase::Init() m_extRight = 0; m_absIndent = -1; m_iFlags = 0; - m_downReceived = false; m_timeCanAcceptClick = 0; } @@ -701,6 +701,9 @@ wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator) { if ( !(m_windowStyle & wxCB_READONLY) ) { + if ( m_text ) + m_text->Destroy(); + // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is // not used by the wxPropertyGrid and therefore the tab is processed by // looking at ancestors to see if they have wxTAB_TRAVERSAL. The @@ -710,6 +713,14 @@ wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator) if ( HasFlag(wxTE_PROCESS_ENTER) ) style |= wxTE_PROCESS_ENTER; + // Ignore EVT_TEXT generated by the constructor (but only + // if the event redirector already exists) + // NB: This must be " = 1" instead of "++"; + if ( m_textEvtHandler ) + m_ignoreEvtText = 1; + else + m_ignoreEvtText = 0; + m_text = new wxTextCtrl(this, wxID_ANY, m_valueString, wxDefaultPosition, wxDefaultSize, style, validator); @@ -729,9 +740,6 @@ wxComboCtrlBase::~wxComboCtrlBase() if ( HasCapture() ) ReleaseMouse(); - delete gs_doubleBuffer; - gs_doubleBuffer = (wxBitmap*) NULL; - #if INSTALL_TOPLEV_HANDLER delete ((wxComboFrameEventHandler*)m_toplevEvtHandler); m_toplevEvtHandler = (wxEvtHandler*) NULL; @@ -878,6 +886,7 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust wxSize sz = GetClientSize(); int customBorder = m_widthCustomBorder; +#if !TEXTCTRL_TEXT_CENTERED if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER ) { // Centre textctrl @@ -904,11 +913,16 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust } } else +#else + wxUnusedVar(textCtrlXAdjust); + wxUnusedVar(textCtrlYAdjust); +#endif { - m_text->SetSize( m_tcArea.x, - 0, - sz.x - m_btnArea.x - m_widthCustomPaint - customBorder, - sz.y ); + // If it has border, have textctrl will the entire text field. + m_text->SetSize( m_tcArea.x + m_widthCustomPaint, + customBorder, + sz.x - m_btnArea.width - m_widthCustomPaint - customBorder, + sz.y-(customBorder*2) ); } } @@ -1230,25 +1244,21 @@ void wxComboCtrlBase::RecalcAndRefresh() } } -wxBitmap& wxComboCtrlBase::GetBufferBitmap( const wxSize& sz ) const -{ - // If size is larger, recalculate double buffer bitmap - if ( !gs_doubleBuffer || - sz.x > gs_doubleBuffer->GetWidth() || - sz.y > gs_doubleBuffer->GetHeight() ) - { - delete gs_doubleBuffer; - gs_doubleBuffer = new wxBitmap(sz.x+25,sz.y); - } - return *gs_doubleBuffer; -} - // ---------------------------------------------------------------------------- // miscellaneous event handlers // ---------------------------------------------------------------------------- void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event) { + if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED ) + { + if ( m_ignoreEvtText > 0 ) + { + m_ignoreEvtText--; + return; + } + } + // Change event id, object and string before relaying it forward event.SetId(GetId()); wxString s = event.GetString(); @@ -1285,26 +1295,17 @@ bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event, } else if ( type == wxEVT_LEFT_DOWN ) { - // Only accept event if it wasn't right after popup dismiss - //if ( ::wxGetLocalTimeMillis() > m_timeCanClick ) + if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) ) { - // Need to test this, because it might be outside. - if ( flags & wxCC_MF_ON_BUTTON ) - { - m_btnState |= wxCONTROL_PRESSED; - Refresh(); + m_btnState |= wxCONTROL_PRESSED; + Refresh(); - if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) ) - OnButtonClick(); - else - // If showing popup now, do not capture mouse or there will be interference - CaptureMouse(); - } + if ( !(m_iFlags & wxCC_POPUP_ON_MOUSE_UP) ) + OnButtonClick(); + else + // If showing popup now, do not capture mouse or there will be interference + CaptureMouse(); } - /*else - { - m_btnState = 0; - }*/ } else if ( type == wxEVT_LEFT_UP ) { @@ -1318,7 +1319,7 @@ bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event, // If mouse was inside, fire the click event. if ( m_iFlags & wxCC_POPUP_ON_MOUSE_UP ) { - if ( flags & wxCC_MF_ON_BUTTON ) + if ( flags & (wxCC_MF_ON_CLICK_AREA|wxCC_MF_ON_BUTTON) ) OnButtonClick(); } @@ -1346,11 +1347,9 @@ bool wxComboCtrlBase::HandleButtonMouseEvent( wxMouseEvent& event, return true; } -// Conversion to double-clicks and some basic filtering // returns true if event was consumed or filtered -//bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, bool isOnButtonArea ) bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, - int flags ) + int WXUNUSED(flags) ) { wxLongLong t = ::wxGetLocalTimeMillis(); int evtType = event.GetEventType(); @@ -1364,48 +1363,6 @@ bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, } #endif - // - // Generate our own double-clicks - // (to allow on-focus dc-event on double-clicks instead of triple-clicks) - if ( (m_windowStyle & wxCC_SPECIAL_DCLICK) && - !m_isPopupShown && - //!(handlerFlags & wxCC_MF_ON_BUTTON) ) - !(flags & wxCC_MF_ON_BUTTON) ) - { - if ( evtType == wxEVT_LEFT_DOWN ) - { - // Set value to avoid up-events without corresponding downs - m_downReceived = true; - } - else if ( evtType == wxEVT_LEFT_DCLICK ) - { - // We'll make our own double-clicks - //evtType = 0; - event.SetEventType(0); - return true; - } - else if ( evtType == wxEVT_LEFT_UP ) - { - if ( m_downReceived || m_timeLastMouseUp == 1 ) - { - wxLongLong timeFromLastUp = (t-m_timeLastMouseUp); - - if ( timeFromLastUp < DOUBLE_CLICK_CONVERSION_TRESHOLD ) - { - //type = wxEVT_LEFT_DCLICK; - event.SetEventType(wxEVT_LEFT_DCLICK); - m_timeLastMouseUp = 1; - } - else - { - m_timeLastMouseUp = t; - } - - //m_downReceived = false; - } - } - } - // Filter out clicks on button immediately after popup dismiss (Windows like behaviour) if ( evtType == wxEVT_LEFT_DOWN && t < m_timeCanAcceptClick ) { @@ -1511,12 +1468,6 @@ void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event ) { if ( event.GetEventType() == wxEVT_SET_FOCUS ) { - // First click is the first part of double-click - // Some platforms don't generate down-less mouse up-event - // (Windows does, GTK+2 doesn't), so that's why we have - // to do this. - m_timeLastMouseUp = ::wxGetLocalTimeMillis(); - if ( m_text && m_text != ::wxWindow::FindFocus() ) m_text->SetFocus(); } @@ -1975,10 +1926,13 @@ wxString wxComboCtrlBase::GetValue() const return m_valueString; } -void wxComboCtrlBase::SetValue(const wxString& value) +void wxComboCtrlBase::SetValueWithEvent(const wxString& value, bool withEvent) { if ( m_text ) { + if ( !withEvent ) + m_ignoreEvtText++; + m_text->SetValue(value); if ( !(m_iFlags & wxCC_NO_TEXT_AUTO_SELECT) ) m_text->SelectAll(); @@ -1996,6 +1950,11 @@ void wxComboCtrlBase::SetValue(const wxString& value) } } +void wxComboCtrlBase::SetValue(const wxString& value) +{ + SetValueWithEvent(value, false); +} + // In this SetValue variant wxComboPopup::SetStringValue is not called void wxComboCtrlBase::SetText(const wxString& value) { @@ -2005,6 +1964,12 @@ void wxComboCtrlBase::SetText(const wxString& value) m_valueString = value; + if ( m_text ) + { + m_ignoreEvtText++; + m_text->SetValue( value ); + } + Refresh(); }