Fix a hack implemented in wxEnumProperty::ValueFromString_ and wxEnumProperty::ValueFromInt_ functions.
wxEnumProperty code is refactored in order to fix a hack which purpose was (apparently) to bypass constness of these functions by caching determined indices in wxEnumProperty::ms_nextIndex static member variable for further processing. (Unclear concept of using this static member was referred in http://trac.wxwidgets.org/ticket/12779#comment:9) Now, determined index is returned to the caller and processed there if necessary and hence caching of this index is not necessary. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78390 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -454,20 +454,34 @@ protected:
|
|||||||
int GetIndex() const;
|
int GetIndex() const;
|
||||||
void SetIndex( int index );
|
void SetIndex( int index );
|
||||||
|
|
||||||
|
#if WXWIN_COMPATIBILITY_3_0
|
||||||
|
wxDEPRECATED_MSG("use ValueFromString_(wxVariant&, int*, const wxString&, int) function instead")
|
||||||
bool ValueFromString_( wxVariant& value,
|
bool ValueFromString_( wxVariant& value,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
int argFlags ) const;
|
int argFlags ) const
|
||||||
bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
|
{
|
||||||
|
return ValueFromString_(value, NULL, text, argFlags);
|
||||||
static void ResetNextIndex() { ms_nextIndex = -2; }
|
}
|
||||||
|
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:
|
private:
|
||||||
// This is private so that classes are guaranteed to use GetIndex
|
// This is private so that classes are guaranteed to use GetIndex
|
||||||
// for up-to-date index value.
|
// for up-to-date index value.
|
||||||
int m_index;
|
int m_index;
|
||||||
|
|
||||||
// Relies on ValidateValue being called always before OnSetValue
|
|
||||||
static int ms_nextIndex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
@@ -1454,13 +1454,11 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te
|
|||||||
{
|
{
|
||||||
// This really should not occur...
|
// This really should not occur...
|
||||||
// wxASSERT(false);
|
// wxASSERT(false);
|
||||||
ResetNextIndex();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !QueryColourFromUser(value) )
|
if ( !QueryColourFromUser(value) )
|
||||||
{
|
{
|
||||||
ResetNextIndex();
|
|
||||||
if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) )
|
if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) )
|
||||||
return false;
|
return false;
|
||||||
// If query for value comes from the event handler
|
// If query for value comes from the event handler
|
||||||
@@ -1477,12 +1475,11 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te
|
|||||||
if ( !conversionSuccess )
|
if ( !conversionSuccess )
|
||||||
{
|
{
|
||||||
// Try predefined colour first
|
// Try predefined colour first
|
||||||
bool res = wxEnumProperty::StringToValue(value,
|
int index;
|
||||||
colStr,
|
bool res = ValueFromString_(value, &index, colStr, argFlags);
|
||||||
argFlags);
|
if ( res && index >= 0 )
|
||||||
if ( res && GetIndex() >= 0 )
|
|
||||||
{
|
{
|
||||||
val.m_type = GetIndex();
|
val.m_type = index;
|
||||||
if ( val.m_type < m_choices.GetCount() )
|
if ( val.m_type < m_choices.GetCount() )
|
||||||
val.m_type = m_choices[val.m_type].GetValue();
|
val.m_type = m_choices[val.m_type].GetValue();
|
||||||
|
|
||||||
@@ -1501,7 +1498,6 @@ bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& te
|
|||||||
|
|
||||||
if ( !done )
|
if ( !done )
|
||||||
{
|
{
|
||||||
ResetNextIndex();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1200,29 +1200,27 @@ wxEnumProperty::~wxEnumProperty ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxEnumProperty::ms_nextIndex = -2;
|
|
||||||
|
|
||||||
void wxEnumProperty::OnSetValue()
|
void wxEnumProperty::OnSetValue()
|
||||||
{
|
{
|
||||||
wxString variantType = m_value.GetType();
|
wxString variantType = m_value.GetType();
|
||||||
|
|
||||||
|
int index = -2;
|
||||||
if ( variantType == wxPG_VARIANT_TYPE_LONG )
|
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 )
|
else if ( variantType == wxPG_VARIANT_TYPE_STRING )
|
||||||
{
|
{
|
||||||
ValueFromString_( m_value, m_value.GetString(), 0 );
|
ValueFromString_(m_value, &index, m_value.GetString(), 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxFAIL;
|
wxFAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ms_nextIndex != -2 )
|
if (index != -2)
|
||||||
{
|
{
|
||||||
m_index = ms_nextIndex;
|
m_index = index;
|
||||||
ms_nextIndex = -2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1233,7 +1231,7 @@ bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUS
|
|||||||
// To reduce code size, use conversion here as well
|
// To reduce code size, use conversion here as well
|
||||||
if ( value.GetType() == wxPG_VARIANT_TYPE_STRING &&
|
if ( value.GetType() == wxPG_VARIANT_TYPE_STRING &&
|
||||||
!wxDynamicCastThis(wxEditEnumProperty) )
|
!wxDynamicCastThis(wxEditEnumProperty) )
|
||||||
return ValueFromString_( value, value.GetString(), wxPG_PROPERTY_SPECIFIC );
|
return ValueFromString_(value, NULL, value.GetString(), wxPG_PROPERTY_SPECIFIC);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -1253,15 +1251,15 @@ wxString wxEnumProperty::ValueToString( wxVariant& value,
|
|||||||
|
|
||||||
bool wxEnumProperty::StringToValue( wxVariant& variant, const wxString& text, int argFlags ) const
|
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
|
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;
|
int useIndex = -1;
|
||||||
long useValue = 0;
|
long useValue = 0;
|
||||||
@@ -1311,20 +1309,24 @@ bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, i
|
|||||||
|
|
||||||
if ( setAsNextIndex != -2 )
|
if ( setAsNextIndex != -2 )
|
||||||
{
|
{
|
||||||
// If wxPG_PROPERTY_SPECIFIC is set, then this is done for
|
if (pIndex)
|
||||||
// validation purposes only, and index must not be changed
|
{
|
||||||
if ( !(argFlags & wxPG_PROPERTY_SPECIFIC) )
|
*pIndex = setAsNextIndex;
|
||||||
ms_nextIndex = setAsNextIndex;
|
}
|
||||||
|
|
||||||
if ( isEdit || setAsNextIndex != -1 )
|
if ( isEdit || setAsNextIndex != -1 )
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (pIndex)
|
||||||
|
{
|
||||||
|
*pIndex = useIndex;
|
||||||
|
}
|
||||||
return false;
|
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.
|
// 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 ( 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) )
|
if ( !(argFlags & wxPG_FULL_VALUE) )
|
||||||
intVal = m_choices.GetValue(intVal);
|
intVal = m_choices.GetValue(intVal);
|
||||||
|
|
||||||
variant = (long)intVal;
|
variant = (long)intVal;
|
||||||
|
|
||||||
|
if (pIndex)
|
||||||
|
{
|
||||||
|
*pIndex = setAsNextIndex;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pIndex)
|
||||||
|
{
|
||||||
|
*pIndex = intVal;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
|
wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
|
||||||
{
|
{
|
||||||
// Revert index
|
|
||||||
ResetNextIndex();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxEnumProperty::SetIndex( int index )
|
void wxEnumProperty::SetIndex( int index )
|
||||||
{
|
{
|
||||||
ms_nextIndex = -2;
|
|
||||||
m_index = index;
|
m_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1378,9 +1380,6 @@ int wxEnumProperty::GetIndex() const
|
|||||||
if ( m_value.IsNull() )
|
if ( m_value.IsNull() )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ( ms_nextIndex != -2 )
|
|
||||||
return ms_nextIndex;
|
|
||||||
|
|
||||||
return m_index;
|
return m_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user