X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1425eca550ca78f6d0824e50376d763aff17242d..08f744fb3be54d7f13c265bc05d3c37fadf67b06:/src/propgrid/props.cpp diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 340d727a73..9014519cee 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -79,7 +79,7 @@ void wxStringProperty::OnSetValue() if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) ) { wxString s; - GenerateComposedValue(s); + DoGenerateComposedValue(s); m_value = s; } } @@ -101,7 +101,7 @@ wxString wxStringProperty::ValueToString( wxVariant& value, "Sorry, currently default wxPGProperty::ValueToString() " "implementation only works if value is m_value." ); - GenerateComposedValue(s, argFlags); + DoGenerateComposedValue(s, argFlags); } return s; @@ -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) +void +wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) ) { - SetIndex(0); - - if ( &labels && labels.size() ) - { - m_choices.Set(labels, values); - - if ( GetItemCount() ) - SetValue( (long)value ); - } + // Revert index + m_index = ms_prevIndex; + ResetNextIndex(); } -wxEnumProperty::wxEnumProperty( const wxString& label, const wxString& name, - wxPGChoices& choices, int value ) - : wxBaseEnumProperty(label,name) +void wxEnumProperty::SetIndex( int index ) { - 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<GetGoodEditorDialogPosition(this,dlg_sz), - dlg_sz ); + dlg_sz #else wxDefaultPosition, - wxDefaultSize ); + wxDefaultSize #endif + ); if ( dlg.ShowModal() == wxID_OK ) { @@ -2110,6 +2068,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; @@ -2173,7 +2132,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)); @@ -2383,7 +2342,7 @@ wxPGArrayStringEditorDialog::wxPGArrayStringEditorDialog() void wxPGArrayStringEditorDialog::Init() { - m_pCallingClass = (wxArrayStringProperty*) NULL; + m_pCallingClass = NULL; } void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent& ) @@ -2455,16 +2414,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; }