diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 8fe0448c76..15e520ee61 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -873,11 +873,7 @@ public: void AssignData( wxPGChoicesData* data ); /** Delete all choices. */ - void Clear() - { - if ( m_data != wxPGChoicesEmptyData ) - m_data->Clear(); - } + void Clear(); /** Returns a real copy of the choices. @@ -980,16 +976,7 @@ public: } // Creates exclusive copy of current choices - void SetExclusive() - { - if ( m_data->m_refCount != 1 ) - { - wxPGChoicesData* data = new wxPGChoicesData(); - data->CopyDataFrom(m_data); - Free(); - m_data = data; - } - } + void AllocExclusive(); // Returns data, increases refcount. wxPGChoicesData* GetData() @@ -1922,14 +1909,6 @@ public: */ void SetValueImage( wxBitmap& bmp ); - /** If property has choices and they are not yet exclusive, new such copy - of them will be created. - */ - void SetChoicesExclusive() - { - m_choices.SetExclusive(); - } - /** Sets selected choice and changes property value. Tries to retain value type, although currently if it is not string, diff --git a/interface/wx/propgrid/property.h b/interface/wx/propgrid/property.h index a8f1465f34..75efba3ce6 100644 --- a/interface/wx/propgrid/property.h +++ b/interface/wx/propgrid/property.h @@ -1273,12 +1273,6 @@ public: */ bool SetChoices( wxPGChoices& choices ); - /** - If property has choices and they are not yet exclusive, new such copy - of them will be created. - */ - void SetChoicesExclusive(); - /** Sets client data (void*) of a property. @@ -1599,7 +1593,7 @@ public: /** Creates exclusive copy of current choices. */ - void SetExclusive(); + void AllocExclusive(); /** Returns array of choice labels. diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index c413502b23..3df4fcd879 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -1494,27 +1494,17 @@ void FormMain::PopulateWithExamples () 240) ); pg->GetProperty(wxT("EnumProperty 2"))->AddChoice(wxT("Testing Extra"), 360); - // Add a second time to test that the caching works. Also use - // short form of constructor list + SetChoices. - prop = new wxEnumProperty(wxT("EnumProperty 3"), wxPG_LABEL); - pg->Append( prop ); - prop->SetChoices(soc); - prop->SetValue(360); - pg->SetPropertyHelpString(prop, - wxT("Should have same choices as EnumProperty 2")); + // Here we only display the original 'soc' choices + pg->Append( new wxEnumProperty(wxT("EnumProperty 3"),wxPG_LABEL, + soc, 240 ) ); + // 'soc' plus one exclusive extra choice "4th only" pg->Append( new wxEnumProperty(wxT("EnumProperty 4"),wxPG_LABEL, soc, 240 ) ); + pg->GetProperty(wxT("EnumProperty 4"))->AddChoice(wxT("4th only"), 360); + pg->SetPropertyHelpString(wxT("EnumProperty 4"), - wxT("Should have same choices as EnumProperty 2")); - - pg->Append( new wxEnumProperty(wxT("EnumProperty 5"),wxPG_LABEL, - soc, 240 ) ); - pg->GetProperty(wxT("EnumProperty 5"))->SetChoicesExclusive(); - pg->GetProperty(wxT("EnumProperty 5"))->AddChoice(wxT("5th only"), 360); - - pg->SetPropertyHelpString(wxT("EnumProperty 5"), - wxT("Should have one extra item when compared to EnumProperty 4")); + wxT("Should have one extra item when compared to EnumProperty 3")); // Password property example. pg->Append( new wxStringProperty(wxT("Password"),wxPG_LABEL, wxT("password")) ); diff --git a/src/propgrid/advprops.cpp b/src/propgrid/advprops.cpp index c151dcb6cd..1b9fa5ee16 100644 --- a/src/propgrid/advprops.cpp +++ b/src/propgrid/advprops.cpp @@ -1423,8 +1423,6 @@ bool wxSystemColourProperty::DoSetAttribute( const wxString& name, wxVariant& va { int ival = wxPGVariantToInt(value); - SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties - if ( ival && (m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR) ) { // Show custom choice diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index dc3d8fc346..bfb0e446e9 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2505,6 +2505,270 @@ void wxPropertyCategory::CalculateTextExtent( wxWindow* wnd, const wxFont& font m_textExtent = x; } +// ----------------------------------------------------------------------- +// wxPGChoices +// ----------------------------------------------------------------------- + +wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, int value ) +{ + AllocExclusive(); + + wxPGChoiceEntry entry(label, value); + return m_data->Insert( -1, entry ); +} + +// ----------------------------------------------------------------------- + +wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, const wxBitmap& bitmap, int value ) +{ + AllocExclusive(); + + wxPGChoiceEntry entry(label, value); + entry.SetBitmap(bitmap); + return m_data->Insert( -1, entry ); +} + +// ----------------------------------------------------------------------- + +wxPGChoiceEntry& wxPGChoices::Insert( const wxPGChoiceEntry& entry, int index ) +{ + AllocExclusive(); + + return m_data->Insert( index, entry ); +} + +// ----------------------------------------------------------------------- + +wxPGChoiceEntry& wxPGChoices::Insert( const wxString& label, int index, int value ) +{ + AllocExclusive(); + + wxPGChoiceEntry entry(label, value); + return m_data->Insert( index, entry ); +} + +// ----------------------------------------------------------------------- + +wxPGChoiceEntry& wxPGChoices::AddAsSorted( const wxString& label, int value ) +{ + AllocExclusive(); + + size_t index = 0; + + while ( index < GetCount() ) + { + int cmpRes = GetLabel(index).Cmp(label); + if ( cmpRes > 0 ) + break; + index++; + } + + wxPGChoiceEntry entry(label, value); + return m_data->Insert( index, entry ); +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::Add( const wxChar** labels, const ValArrItem* values ) +{ + AllocExclusive(); + + unsigned int itemcount = 0; + const wxChar** p = &labels[0]; + while ( *p ) { p++; itemcount++; } + + unsigned int i; + for ( i = 0; i < itemcount; i++ ) + { + int value = i; + if ( values ) + value = values[i]; + wxPGChoiceEntry entry(labels[i], value); + m_data->Insert( i, entry ); + } +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint ) +{ + AllocExclusive(); + + unsigned int i; + unsigned int itemcount = arr.size(); + + for ( i = 0; i < itemcount; i++ ) + { + int value = i; + if ( &arrint && arrint.size() ) + value = arrint[i]; + wxPGChoiceEntry entry(arr[i], value); + m_data->Insert( i, entry ); + } +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::RemoveAt(size_t nIndex, size_t count) +{ + AllocExclusive(); + + wxASSERT( m_data->m_refCount != 0xFFFFFFF ); + m_data->m_items.erase(m_data->m_items.begin()+nIndex, + m_data->m_items.begin()+nIndex+count); +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::Clear() +{ + if ( m_data != wxPGChoicesEmptyData ) + { + AllocExclusive(); + m_data->Clear(); + } +} + +// ----------------------------------------------------------------------- + +int wxPGChoices::Index( const wxString& str ) const +{ + if ( IsOk() ) + { + unsigned int i; + for ( i=0; i< m_data->GetCount(); i++ ) + { + const wxPGChoiceEntry& entry = m_data->Item(i); + if ( entry.HasText() && entry.GetText() == str ) + return i; + } + } + return -1; +} + +// ----------------------------------------------------------------------- + +int wxPGChoices::Index( int val ) const +{ + if ( IsOk() ) + { + unsigned int i; + for ( i=0; i< m_data->GetCount(); i++ ) + { + const wxPGChoiceEntry& entry = m_data->Item(i); + if ( entry.GetValue() == val ) + return i; + } + } + return -1; +} + +// ----------------------------------------------------------------------- + +wxArrayString wxPGChoices::GetLabels() const +{ + wxArrayString arr; + unsigned int i; + + if ( this && IsOk() ) + for ( i=0; i= 0 ) + arr.Add(GetValue(index)); + else + arr.Add(wxPG_INVALID_VALUE); + } + } + + return arr; +} + +// ----------------------------------------------------------------------- + +wxArrayInt wxPGChoices::GetIndicesForStrings( const wxArrayString& strings, + wxArrayString* unmatched ) const +{ + wxArrayInt arr; + + if ( IsOk() ) + { + unsigned int i; + for ( i=0; i< strings.size(); i++ ) + { + const wxString& str = strings[i]; + int index = Index(str); + if ( index >= 0 ) + arr.Add(index); + else if ( unmatched ) + unmatched->Add(str); + } + } + + return arr; +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::AllocExclusive() +{ + EnsureData(); + + if ( m_data->m_refCount != 1 ) + { + wxPGChoicesData* data = new wxPGChoicesData(); + data->CopyDataFrom(m_data); + Free(); + m_data = data; + } +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::AssignData( wxPGChoicesData* data ) +{ + Free(); + + if ( data != wxPGChoicesEmptyData ) + { + m_data = data; + data->m_refCount++; + } +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::Init() +{ + m_data = wxPGChoicesEmptyData; +} + +// ----------------------------------------------------------------------- + +void wxPGChoices::Free() +{ + if ( m_data != wxPGChoicesEmptyData ) + { + m_data->DecRef(); + m_data = wxPGChoicesEmptyData; + } +} + // ----------------------------------------------------------------------- // wxPGAttributeStorage // ----------------------------------------------------------------------- diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 764f7e820e..c5167ba145 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -5287,241 +5287,6 @@ wxPGChoiceEntry& wxPGChoicesData::Insert( int index, return ownEntry; } -// ----------------------------------------------------------------------- -// wxPGChoices -// ----------------------------------------------------------------------- - -wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, int value ) -{ - EnsureData(); - - wxPGChoiceEntry entry(label, value); - return m_data->Insert( -1, entry ); -} - -// ----------------------------------------------------------------------- - -wxPGChoiceEntry& wxPGChoices::Add( const wxString& label, const wxBitmap& bitmap, int value ) -{ - EnsureData(); - - wxPGChoiceEntry entry(label, value); - entry.SetBitmap(bitmap); - return m_data->Insert( -1, entry ); -} - -// ----------------------------------------------------------------------- - -wxPGChoiceEntry& wxPGChoices::Insert( const wxPGChoiceEntry& entry, int index ) -{ - EnsureData(); - return m_data->Insert( index, entry ); -} - -// ----------------------------------------------------------------------- - -wxPGChoiceEntry& wxPGChoices::Insert( const wxString& label, int index, int value ) -{ - EnsureData(); - - wxPGChoiceEntry entry(label, value); - return m_data->Insert( index, entry ); -} - -// ----------------------------------------------------------------------- - -wxPGChoiceEntry& wxPGChoices::AddAsSorted( const wxString& label, int value ) -{ - EnsureData(); - - size_t index = 0; - - while ( index < GetCount() ) - { - int cmpRes = GetLabel(index).Cmp(label); - if ( cmpRes > 0 ) - break; - index++; - } - - wxPGChoiceEntry entry(label, value); - return m_data->Insert( index, entry ); -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::Add( const wxChar** labels, const ValArrItem* values ) -{ - EnsureData(); - - unsigned int itemcount = 0; - const wxChar** p = &labels[0]; - while ( *p ) { p++; itemcount++; } - - unsigned int i; - for ( i = 0; i < itemcount; i++ ) - { - int value = i; - if ( values ) - value = values[i]; - wxPGChoiceEntry entry(labels[i], value); - m_data->Insert( i, entry ); - } -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint ) -{ - EnsureData(); - - unsigned int i; - unsigned int itemcount = arr.size(); - - for ( i = 0; i < itemcount; i++ ) - { - int value = i; - if ( &arrint && arrint.size() ) - value = arrint[i]; - wxPGChoiceEntry entry(arr[i], value); - m_data->Insert( i, entry ); - } -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::RemoveAt(size_t nIndex, size_t count) -{ - wxASSERT( m_data->m_refCount != 0xFFFFFFF ); - m_data->m_items.erase(m_data->m_items.begin()+nIndex, - m_data->m_items.begin()+nIndex+count); -} - -// ----------------------------------------------------------------------- - -int wxPGChoices::Index( const wxString& str ) const -{ - if ( IsOk() ) - { - unsigned int i; - for ( i=0; i< m_data->GetCount(); i++ ) - { - const wxPGChoiceEntry& entry = m_data->Item(i); - if ( entry.HasText() && entry.GetText() == str ) - return i; - } - } - return -1; -} - -// ----------------------------------------------------------------------- - -int wxPGChoices::Index( int val ) const -{ - if ( IsOk() ) - { - unsigned int i; - for ( i=0; i< m_data->GetCount(); i++ ) - { - const wxPGChoiceEntry& entry = m_data->Item(i); - if ( entry.GetValue() == val ) - return i; - } - } - return -1; -} - -// ----------------------------------------------------------------------- - -wxArrayString wxPGChoices::GetLabels() const -{ - wxArrayString arr; - unsigned int i; - - if ( this && IsOk() ) - for ( i=0; i= 0 ) - arr.Add(GetValue(index)); - else - arr.Add(wxPG_INVALID_VALUE); - } - } - - return arr; -} - -// ----------------------------------------------------------------------- - -wxArrayInt wxPGChoices::GetIndicesForStrings( const wxArrayString& strings, - wxArrayString* unmatched ) const -{ - wxArrayInt arr; - - if ( IsOk() ) - { - unsigned int i; - for ( i=0; i< strings.size(); i++ ) - { - const wxString& str = strings[i]; - int index = Index(str); - if ( index >= 0 ) - arr.Add(index); - else if ( unmatched ) - unmatched->Add(str); - } - } - - return arr; -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::AssignData( wxPGChoicesData* data ) -{ - Free(); - - if ( data != wxPGChoicesEmptyData ) - { - m_data = data; - data->m_refCount++; - } -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::Init() -{ - m_data = wxPGChoicesEmptyData; -} - -// ----------------------------------------------------------------------- - -void wxPGChoices::Free() -{ - if ( m_data != wxPGChoicesEmptyData ) - { - m_data->DecRef(); - m_data = wxPGChoicesEmptyData; - } -} - // ----------------------------------------------------------------------- // wxPropertyGridEvent // -----------------------------------------------------------------------