X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd8b65be3d23b530c85b01b124540db8bdedc1b7..55410bb4f67febe1ca20654f078ea4fb9a6223ae:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index a182229cc9..9014519cee 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -200,7 +200,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int int firstNonZeroPos = 0; - for ( ; i != iMax; i++ ) + for ( ; i != iMax; ++i ) { wxChar c = *i; if ( c != wxS('0') && c != wxS(' ') ) @@ -606,7 +606,7 @@ void wxPropertyGrid::DoubleToString(wxString& target, wxString::const_iterator i = target.end() - 1; size_t new_len = target.length() - 1; - for ( ; i != target.begin(); i-- ) + for ( ; i != target.begin(); --i ) { if ( *i != wxS('0') ) break; @@ -632,7 +632,7 @@ wxString wxFloatProperty::ValueToString( wxVariant& value, value, m_precision, !(argFlags & wxPG_FULL_VALUE), - (wxString*) NULL); + NULL); } return text; } @@ -878,26 +878,94 @@ bool wxBoolProperty::DoSetAttribute( const wxString& name, wxVariant& value ) } // ----------------------------------------------------------------------- -// wxBaseEnumProperty +// wxEnumProperty // ----------------------------------------------------------------------- -int wxBaseEnumProperty::ms_nextIndex = -2; +IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty, wxPGProperty) + +WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty,long,Choice) + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels, + const long* values, int value ) : wxPGProperty(label,name) +{ + SetIndex(0); + + if ( labels ) + { + m_choices.Add(labels,values); + + if ( GetItemCount() ) + SetValue( (long)value ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, const wxChar** labels, + const long* values, wxPGChoices* choicesCache, int value ) + : wxPGProperty(label,name) +{ + SetIndex(0); + + wxASSERT( choicesCache ); + + if ( choicesCache->IsOk() ) + { + m_choices.Assign( *choicesCache ); + m_value = wxPGVariant_Zero; + } + else if ( labels ) + { + m_choices.Add(labels,values); + + if ( GetItemCount() ) + SetValue( (long)value ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, + const wxArrayString& labels, const wxArrayInt& values, int value ) + : wxPGProperty(label,name) +{ + SetIndex(0); + + if ( &labels && labels.size() ) + { + m_choices.Set(labels, values); + + if ( GetItemCount() ) + SetValue( (long)value ); + } +} -wxBaseEnumProperty::wxBaseEnumProperty( const wxString& label, const wxString& name ) +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, + wxPGChoices& choices, int value ) : wxPGProperty(label,name) { - m_value = wxPGVariant_Zero; + m_choices.Assign( choices ); + + if ( GetItemCount() ) + SetValue( (long)value ); } -/** If has values array, then returns number at index with value - - otherwise just returns the value. -*/ -int wxBaseEnumProperty::GetIndexForValue( int value ) const +int wxEnumProperty::GetIndexForValue( int value ) const { + if ( !m_choices.IsOk() ) + return -1; + + int intVal = m_choices.Index(value); + if ( intVal >= 0 ) + return intVal; + return value; } -void wxBaseEnumProperty::OnSetValue() +wxEnumProperty::~wxEnumProperty () +{ +} + +int wxEnumProperty::ms_nextIndex = -2; +int wxEnumProperty::ms_prevIndex = -1; + +void wxEnumProperty::OnSetValue() { wxString variantType = m_value.GetType(); @@ -906,7 +974,7 @@ void wxBaseEnumProperty::OnSetValue() else if ( variantType == wxPG_VARIANT_TYPE_STRING ) ValueFromString_( m_value, m_value.GetString(), 0 ); else - wxASSERT( false ); + wxFAIL; if ( ms_nextIndex != -2 ) { @@ -915,7 +983,7 @@ void wxBaseEnumProperty::OnSetValue() } } -bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUSED(validationInfo) ) const +bool wxEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WXUNUSED(validationInfo) ) const { // Make sure string value is in the list, // unless property has string as preferred value type @@ -927,7 +995,7 @@ bool wxBaseEnumProperty::ValidateValue( wxVariant& value, wxPGValidationInfo& WX return true; } -wxString wxBaseEnumProperty::ValueToString( wxVariant& value, +wxString wxEnumProperty::ValueToString( wxVariant& value, int WXUNUSED(argFlags) ) const { if ( value.GetType() == wxPG_VARIANT_TYPE_STRING ) @@ -940,36 +1008,30 @@ wxString wxBaseEnumProperty::ValueToString( wxVariant& value, return m_choices.GetLabel(index); } -bool wxBaseEnumProperty::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 ); } -bool wxBaseEnumProperty::IntToValue( wxVariant& variant, int intVal, int argFlags ) const +bool wxEnumProperty::IntToValue( wxVariant& variant, int intVal, int argFlags ) const { return ValueFromInt_( variant, intVal, argFlags ); } -bool wxBaseEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, int argFlags ) const +bool wxEnumProperty::ValueFromString_( wxVariant& value, const wxString& text, int argFlags ) const { - size_t i = 0; - const wxString* entryLabel; - int entryValue; int useIndex = -1; long useValue = 0; - entryLabel = GetEntry(i, &entryValue); - while ( entryLabel ) + for ( unsigned int i=0; iIsOk() ) - { - m_choices.Assign( *choicesCache ); - m_value = wxPGVariant_Zero; - } - else if ( labels ) - { - m_choices.Add(labels,values); - - if ( GetItemCount() ) - SetValue( (long)value ); - } -} - -wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, - const wxArrayString& labels, const wxArrayInt& values, int value ) : wxBaseEnumProperty(label,name) -{ - SetIndex(0); - - if ( &labels && labels.size() ) - { - m_choices.Set(labels, values); - - if ( GetItemCount() ) - SetValue( (long)value ); - } -} - -wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, - wxPGChoices& choices, int value ) - : wxBaseEnumProperty(label,name) -{ - m_choices.Assign( choices ); - - if ( GetItemCount() ) - SetValue( (long)value ); + ms_prevIndex = m_index; + ms_nextIndex = -2; + m_index = index; } -int wxEnumProperty::GetIndexForValue( int value ) const +int wxEnumProperty::GetIndex() const { - if ( !m_choices.IsOk() ) + if ( m_value.IsNull() ) return -1; - if ( m_choices.HasValues() ) - { - int intVal = m_choices.Index(value); - if ( intVal >= 0 ) - return intVal; - } - - return value; -} - -wxEnumProperty::~wxEnumProperty () -{ -} - -const wxString* wxEnumProperty::GetEntry( size_t index, int* pvalue ) const -{ - if ( m_choices.IsOk() && index < m_choices.GetCount() ) - { - int value = (int)index; - if ( m_choices.HasValue(index) ) - value = m_choices.GetValue(index); - - if ( pvalue ) - *pvalue = value; + if ( ms_nextIndex != -2 ) + return ms_nextIndex; - return &m_choices.GetLabel(index); - } - return (const wxString*) NULL; + return m_index; } // ----------------------------------------------------------------------- @@ -1264,10 +1236,7 @@ void wxFlagsProperty::Init() for ( i=0; iSetFlag( wxPG_PROP_MODIFIED ); @@ -1431,10 +1394,7 @@ wxString wxFlagsProperty::ValueToString( wxVariant& value, for ( i = 0; i < GetItemCount(); i++ ) { int doAdd; - if ( choices.HasValue(i) ) - doAdd = ( flags & choices.GetValue(i) ); - else - doAdd = ( flags & (1<