X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98c0463399a5787ea9bf8644e2c4cacf2c98e214..beb2638a997914bd12c55e81589adebd90af9ed2:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 1b61ba15df..3558201abc 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,93 @@ 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) -wxBaseEnumProperty::wxBaseEnumProperty( const wxString& label, const wxString& name ) +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) { - m_value = wxPGVariant_Zero; + 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 ); + } } -/** If has values array, then returns number at index with value - - otherwise just returns the value. -*/ -int wxBaseEnumProperty::GetIndexForValue( int value ) const +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 ); + } +} + +wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, + wxPGChoices& choices, int value ) + : wxPGProperty(label,name) +{ + m_choices.Assign( choices ); + + if ( GetItemCount() ) + SetValue( (long)value ); +} + +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; + +void wxEnumProperty::OnSetValue() { wxString variantType = m_value.GetType(); @@ -906,7 +973,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 +982,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 +994,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 +1007,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_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; - 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 = 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; } // ----------------------------------------------------------------------- @@ -1213,8 +1187,6 @@ WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty,long,TextCtrl) void wxFlagsProperty::Init() { - SetParentalType(wxPG_PROP_AGGREGATE); - long value = m_value; // @@ -1274,7 +1246,7 @@ void wxFlagsProperty::Init() { boolProp = new wxBoolProperty( label, label, child_val ); } - AddChild(boolProp); + AddPrivateChild(boolProp); } m_oldChoicesData = m_choices.GetDataPtr(); @@ -1289,7 +1261,7 @@ void wxFlagsProperty::Init() wxFlagsProperty::wxFlagsProperty( const wxString& label, const wxString& name, const wxChar** labels, const long* values, long value ) : wxPGProperty(label,name) { - m_oldChoicesData = (wxPGChoicesData*) NULL; + m_oldChoicesData = NULL; if ( labels ) { @@ -1309,7 +1281,7 @@ wxFlagsProperty::wxFlagsProperty( const wxString& label, const wxString& name, const wxArrayString& labels, const wxArrayInt& values, int value ) : wxPGProperty(label,name) { - m_oldChoicesData = (wxPGChoicesData*) NULL; + m_oldChoicesData = NULL; if ( &labels && labels.size() ) { @@ -1329,7 +1301,7 @@ wxFlagsProperty::wxFlagsProperty( const wxString& label, const wxString& name, wxPGChoices& choices, long value ) : wxPGProperty(label,name) { - m_oldChoicesData = (wxPGChoicesData*) NULL; + m_oldChoicesData = NULL; if ( choices.IsOk() ) { @@ -2091,6 +2063,7 @@ bool wxArrayEditorDialog::Create( wxWindow *parent, // On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION // FIXME: This should be only a temporary fix. #ifdef __WXMAC__ + wxUnusedVar(style); int useStyle = wxCAPTION; #else int useStyle = style; @@ -2154,7 +2127,7 @@ bool wxArrayEditorDialog::Create( wxWindow *parent, // Manipulator buttons wxBoxSizer* colsizer = new wxBoxSizer( wxVERTICAL ); - m_butCustom = (wxButton*) NULL; + m_butCustom = NULL; if ( m_custBtText ) { m_butCustom = new wxButton(this,28,::wxGetTranslation(m_custBtText)); @@ -2364,7 +2337,7 @@ wxPGArrayStringEditorDialog::wxPGArrayStringEditorDialog() void wxPGArrayStringEditorDialog::Init() { - m_pCallingClass = (wxArrayStringProperty*) NULL; + m_pCallingClass = NULL; } void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent& ) @@ -2436,16 +2409,13 @@ void wxPropertyGrid::ArrayStringToString( wxString& dst, const wxArrayString& sr unsigned int i; unsigned int itemCount = src.size(); - wxChar preas[2]; + wxChar preas[2] = { 0, 0 }; dst.Empty(); - if ( !preDelim ) - preas[0] = 0; - else if ( (flags & 1) ) + if ( flags & 1 ) { preas[0] = preDelim; - preas[1] = 0; pdr = wxS("\\"); pdr += preDelim; }