X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8812c6e0e780fb2dae99bc352c5061f58793e14..a721fd82b7ca8c97048453d4aaff559e8f741d69:/include/wx/propgrid/property.h diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 176db3d61e..15e520ee61 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -737,6 +737,11 @@ private: Helper class for managing choices of wxPropertyGrid properties. Each entry can have label, value, bitmap, text colour, and background colour. + + wxPGChoices uses reference counting, similar to other wxWidgets classes. + This means that assignment operator and copy constructor only copy the + reference and not the actual data. Use Copy() member function to create a + real copy. @remarks If you do not specify value for entry, index is used. @@ -754,7 +759,10 @@ public: Init(); } - /** Copy constructor. */ + /** + Copy constructor, uses reference counting. To create a real copy, + use Copy() member function instead. + */ wxPGChoices( const wxPGChoices& a ) { if ( a.m_data != wxPGChoicesEmptyData ) @@ -853,6 +861,10 @@ public: wxPGChoiceEntry& AddAsSorted( const wxString& label, int value = wxPG_INVALID_VALUE ); + /** + Assigns choices data, using reference counting. To create a real copy, + use Copy() member function instead. + */ void Assign( const wxPGChoices& a ) { AssignData(a.m_data); @@ -861,10 +873,17 @@ public: void AssignData( wxPGChoicesData* data ); /** Delete all choices. */ - void Clear() + void Clear(); + + /** + Returns a real copy of the choices. + */ + wxPGChoices Copy() const { - if ( m_data != wxPGChoicesEmptyData ) - m_data->Clear(); + wxPGChoices dst; + dst.EnsureData(); + dst.m_data->CopyDataFrom(m_data); + return dst; } void EnsureData() @@ -957,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() @@ -1899,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, @@ -2335,7 +2337,7 @@ public: public: /** Constructor. */ - wxPGRootProperty(); + wxPGRootProperty( const wxString& name = wxS("") ); virtual ~wxPGRootProperty(); virtual bool StringToValue( wxVariant&, const wxString&, int ) const