diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index f9fc77d510..bce7185acf 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -454,20 +454,34 @@ protected: int GetIndex() const; void SetIndex( int index ); +#if WXWIN_COMPATIBILITY_3_0 + wxDEPRECATED_MSG("use ValueFromString_(wxVariant&, int*, const wxString&, int) function instead") bool ValueFromString_( wxVariant& value, const wxString& text, - int argFlags ) const; - bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const; - - static void ResetNextIndex() { ms_nextIndex = -2; } + int argFlags ) const + { + return ValueFromString_(value, NULL, text, argFlags); + } + wxDEPRECATED_MSG("use ValueFromInt_(wxVariant&, int*, int, int) function instead") + bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const + { + return ValueFromInt_(value, NULL, intVal, argFlags); + } + wxDEPRECATED_MSG("don't use ResetNextIndex() function") + static void ResetNextIndex() { } +#endif + // Converts text to value and returns corresponding index in the collection + bool ValueFromString_(wxVariant& value, + int* pIndex, + const wxString& text, + int argFlags) const; + // Converts number to value and returns corresponding index in the collection + bool ValueFromInt_(wxVariant& value, int* pIndex, int intVal, int argFlags) const; private: // This is private so that classes are guaranteed to use GetIndex // for up-to-date index value. int m_index; - - // Relies on ValidateValue being called always before OnSetValue - static int ms_nextIndex; }; // ----------------------------------------------------------------------- diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index 807b1509d8..4f39b4a780 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -1454,13 +1454,11 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te { // This really should not occur... // wxASSERT(false); - ResetNextIndex(); return false; } if ( !QueryColourFromUser(value) ) { - ResetNextIndex(); if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) ) return false; // If query for value comes from the event handler @@ -1477,12 +1475,11 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te if ( !conversionSuccess ) { // Try predefined colour first - bool res = wxEnumProperty::StringToValue(value, - colStr, - argFlags); - if ( res && GetIndex() >= 0 ) + int index; + bool res = ValueFromString_(value, &index, colStr, argFlags); + if ( res && index >= 0 ) { - val.m_type = GetIndex(); + val.m_type = index; if ( val.m_type < m_choices.GetCount() ) val.m_type = m_choices[val.m_type].GetValue(); @@ -1501,7 +1498,6 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te if ( !done ) { - ResetNextIndex(); return false; } diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 2cf2ddd8eb..b6d3fa6249 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -1200,29 +1200,27 @@ wxEnumProperty::~wxEnumProperty () { } -int wxEnumProperty::ms_nextIndex = -2; - void wxEnumProperty::OnSetValue() { wxString variantType = m_value.GetType(); + int index = -2; if ( variantType == wxPG_VARIANT_TYPE_LONG ) { - ValueFromInt_( m_value, m_value.GetLong(), wxPG_FULL_VALUE ); + ValueFromInt_(m_value, &index, m_value.GetLong(), wxPG_FULL_VALUE); } else if ( variantType == wxPG_VARIANT_TYPE_STRING ) { - ValueFromString_( m_value, m_value.GetString(), 0 ); + ValueFromString_(m_value, &index, m_value.GetString(), 0); } else { wxFAIL; } - if ( ms_nextIndex != -2 ) + if (index != -2) { - m_index = ms_nextIndex; - ms_nextIndex = -2; + m_index = index; } } @@ -1233,7 +1231,7 @@ bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUS // To reduce code size, use conversion here as well if ( value.GetType() == wxPG_VARIANT_TYPE_STRING && !wxDynamicCastThis(wxEditEnumProperty) ) - return ValueFromString_( value, value.GetString(), wxPG_PROPERTY_SPECIFIC ); + return ValueFromString_(value, NULL, value.GetString(), wxPG_PROPERTY_SPECIFIC); return true; } @@ -1253,15 +1251,15 @@ wxString wxEnumProperty::ValueToString( wxVariant& value, bool wxEnumProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const { - return ValueFromString_( variant, text, argFlags ); + return ValueFromString_(variant, NULL, text, argFlags); } bool wxEnumProperty::IntToValue( wxVariant& variant, int intVal, int argFlags ) const { - return ValueFromInt_( variant, intVal, argFlags ); + return ValueFromInt_(variant, NULL, intVal, argFlags); } -bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, int argFlags ) const +bool wxEnumProperty::ValueFromString_(wxVariant& value, int* pIndex, const wxString& text, int WXUNUSED(argFlags)) const { int useIndex = -1; long useValue = 0; @@ -1311,20 +1309,24 @@ bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, i if ( setAsNextIndex != -2 ) { - // If wxPG_PROPERTY_SPECIFIC is set, then this is done for - // validation purposes only, and index must not be changed - if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) ) - ms_nextIndex = setAsNextIndex; + if (pIndex) + { + *pIndex = setAsNextIndex; + } if ( isEdit || setAsNextIndex != -1 ) return true; else return false; } + if (pIndex) + { + *pIndex = useIndex; + } return false; } -bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags ) const +bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int* pIndex, int intVal, int argFlags ) const { // If wxPG_FULL_VALUE is *not* in argFlags, then intVal is index from combo box. // @@ -1344,32 +1346,32 @@ bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags if ( setAsNextIndex != -2 ) { - // If wxPG_PROPERTY_SPECIFIC is set, then this is done for - // validation or fetching a data purposes only, and index must not be changed. - if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) ) - ms_nextIndex = setAsNextIndex; - if ( !(argFlags & wxPG_FULL_VALUE) ) intVal = m_choices.GetValue(intVal); variant = (long)intVal; + if (pIndex) + { + *pIndex = setAsNextIndex; + } return true; } + if (pIndex) + { + *pIndex = intVal; + } return false; } void wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) ) { - // Revert index - ResetNextIndex(); } void wxEnumProperty::SetIndex( int index ) { - ms_nextIndex = -2; m_index = index; } @@ -1378,9 +1380,6 @@ int wxEnumProperty::GetIndex() const if ( m_value.IsNull() ) return -1; - if ( ms_nextIndex != -2 ) - return ms_nextIndex; - return m_index; }