+
+/** @class wxPGChoices
+
+ 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.
+
+ @library{wxpropgrid}
+ @category{propgrid}
+*/
+class WXDLLIMPEXP_PROPGRID wxPGChoices
+{
+public:
+ typedef long ValArrItem;
+
+ /** Default constructor. */
+ wxPGChoices()
+ {
+ Init();
+ }
+
+ /**
+ Copy constructor, uses reference counting. To create a real copy,
+ use Copy() member function instead.
+ */
+ wxPGChoices( const wxPGChoices& a )
+ {
+ if ( a.m_data != wxPGChoicesEmptyData )
+ {
+ m_data = a.m_data;
+ m_data->IncRef();
+ }
+ }
+
+ /**
+ Constructor.
+
+ @param labels
+ Labels for choices
+
+ @param values
+ Values for choices. If NULL, indexes are used.
+ */
+ wxPGChoices( const wxChar* const* labels, const long* values = NULL )
+ {
+ Init();
+ Set(labels,values);
+ }
+
+ /**
+ Constructor.
+
+ @param labels
+ Labels for choices
+
+ @param values
+ Values for choices. If empty, indexes are used.
+ */
+ wxPGChoices( const wxArrayString& labels,
+ const wxArrayInt& values = wxArrayInt() )
+ {
+ Init();
+ Set(labels,values);
+ }
+
+ /** Simple interface constructor. */
+ wxPGChoices( wxPGChoicesData* data )
+ {
+ wxASSERT(data);
+ m_data = data;
+ data->IncRef();
+ }
+
+ /** Destructor. */
+ ~wxPGChoices()
+ {
+ Free();
+ }
+
+ /**
+ Adds to current.
+
+ If did not have own copies, creates them now. If was empty, identical
+ to set except that creates copies.
+
+ @param labels
+ Labels for added choices.
+
+ @param values
+ Values for added choices. If empty, relevant entry indexes are used.
+ */
+ void Add( const wxChar* const* labels, const ValArrItem* values = NULL );
+
+ /** Version that works with wxArrayString and wxArrayInt. */
+ void Add( const wxArrayString& arr, const wxArrayInt& arrint = wxArrayInt() );
+
+ /**
+ Adds a single choice.
+
+ @param label
+ Label for added choice.
+
+ @param value
+ Value for added choice. If unspecified, index is used.
+ */
+ wxPGChoiceEntry& Add( const wxString& label,
+ int value = wxPG_INVALID_VALUE );
+
+ /** Adds a single item, with bitmap. */
+ wxPGChoiceEntry& Add( const wxString& label,
+ const wxBitmap& bitmap,
+ int value = wxPG_INVALID_VALUE );
+
+ /** Adds a single item with full entry information. */
+ wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
+ {
+ return Insert(entry, -1);
+ }
+
+ /** Adds single item. */
+ 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);
+ }
+
+ void AssignData( wxPGChoicesData* data );
+
+ /** Delete all choices. */
+ void Clear();
+
+ /**
+ Returns a real copy of the choices.
+ */
+ wxPGChoices Copy() const
+ {
+ wxPGChoices dst;
+ dst.EnsureData();
+ dst.m_data->CopyDataFrom(m_data);
+ return dst;
+ }
+
+ void EnsureData()
+ {
+ if ( m_data == wxPGChoicesEmptyData )
+ m_data = new wxPGChoicesData();
+ }
+
+ /** Gets a unsigned number identifying this list. */
+ wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; }
+
+ const wxString& GetLabel( unsigned int ind ) const
+ {
+ return Item(ind).GetText();
+ }
+
+ unsigned int GetCount () const
+ {
+ if ( !m_data )
+ return 0;
+
+ return m_data->GetCount();
+ }
+
+ int GetValue( unsigned int ind ) const { return Item(ind).GetValue(); }
+
+ /** Returns array of values matching the given strings. Unmatching strings
+ result in wxPG_INVALID_VALUE entry in array.
+ */
+ wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
+
+ /** Returns array of indices matching given strings. Unmatching strings
+ are added to 'unmatched', if not NULL.
+ */
+ wxArrayInt GetIndicesForStrings( const wxArrayString& strings,
+ wxArrayString* unmatched = NULL ) const;
+
+ int Index( const wxString& str ) const;
+ int Index( int val ) const;
+
+ /** Inserts single item. */
+ wxPGChoiceEntry& Insert( const wxString& label,
+ int index,
+ int value = wxPG_INVALID_VALUE );
+
+ /** Inserts a single item with full entry information. */
+ wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
+
+ /** Returns false if this is a constant empty set of choices,
+ which should not be modified.
+ */
+ bool IsOk() const
+ {
+ return ( m_data != wxPGChoicesEmptyData );
+ }
+
+ const wxPGChoiceEntry& Item( unsigned int i ) const
+ {
+ wxASSERT( IsOk() );
+ return m_data->Item(i);
+ }
+
+ wxPGChoiceEntry& Item( unsigned int i )
+ {
+ wxASSERT( IsOk() );
+ return m_data->Item(i);
+ }
+
+ /** Removes count items starting at position nIndex. */
+ void RemoveAt(size_t nIndex, size_t count = 1);
+
+ /** Does not create copies for itself.
+ TODO: Deprecate.
+ */
+ void Set( const wxChar* const* labels, const long* values = NULL )
+ {
+ Free();
+ Add(labels,values);
+ }
+
+ /** Version that works with wxArrayString and wxArrayInt. */
+ void Set( const wxArrayString& labels,
+ const wxArrayInt& values = wxArrayInt() )
+ {
+ Free();
+ if ( &values )
+ Add(labels,values);
+ else
+ Add(labels);
+ }
+
+ // Creates exclusive copy of current choices
+ void AllocExclusive();
+
+ // Returns data, increases refcount.
+ wxPGChoicesData* GetData()
+ {
+ wxASSERT( m_data->GetRefCount() != -1 );
+ m_data->IncRef();
+ return m_data;
+ }
+
+ // Returns plain data ptr - no refcounting stuff is done.
+ wxPGChoicesData* GetDataPtr() const { return m_data; }
+
+ // Changes ownership of data to you.
+ wxPGChoicesData* ExtractData()
+ {
+ wxPGChoicesData* data = m_data;
+ m_data = wxPGChoicesEmptyData;
+ return data;
+ }
+
+ wxArrayString GetLabels() const;
+
+ void operator= (const wxPGChoices& a)
+ {
+ if (this != &a)
+ AssignData(a.m_data);
+ }
+
+ wxPGChoiceEntry& operator[](unsigned int i)
+ {
+ return Item(i);
+ }
+
+ const wxPGChoiceEntry& operator[](unsigned int i) const
+ {
+ return Item(i);
+ }
+
+protected:
+ wxPGChoicesData* m_data;
+
+ void Init();
+ void Free();
+};
+
+// -----------------------------------------------------------------------
+
+/** @class wxPGProperty
+
+ wxPGProperty is base class for all wxPropertyGrid properties.
+
+ NB: Full class overview is now only present in
+ interface/wx/propgrid/property.h.
+
+ @library{wxpropgrid}
+ @category{propgrid}
+*/
+class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
+{
+ friend class wxPropertyGrid;
+ friend class wxPropertyGridInterface;
+ friend class wxPropertyGridPageState;
+ friend class wxPropertyGridPopulator;
+ friend class wxStringProperty; // Proper "<composed>" support requires this
+
+ DECLARE_ABSTRACT_CLASS(wxPGProperty)
+public:
+ typedef wxUint32 FlagType;
+
+ /**
+ Default constructor.
+ */
+ wxPGProperty();
+
+ /**
+ Constructor.
+
+ All non-abstract property classes should have a constructor with
+ the same first two arguments as this one.
+ */
+ wxPGProperty( const wxString& label, const wxString& name );
+
+ /**
+ Virtual destructor.
+ It is customary for derived properties to implement this.
+ */
+ virtual ~wxPGProperty();
+
+ /** This virtual function is called after m_value has been set.
+
+ @remarks
+ - If m_value was set to Null variant (ie. unspecified value),
+ OnSetValue() will not be called.
+ - m_value may be of any variant type. Typically properties internally
+ support only one variant type, and as such OnSetValue() provides a
+ good opportunity to convert
+ supported values into internal type.
+ - Default implementation does nothing.
+ */
+ virtual void OnSetValue();
+
+ /** Override this to return something else than m_value as the value.
+ */
+ virtual wxVariant DoGetValue() const { return m_value; }
+
+ /** Implement this function in derived class to check the value.
+ Return true if it is ok. Returning false prevents property change events
+ from occurring.
+
+ @remarks
+ - Default implementation always returns true.
+ */
+ virtual bool ValidateValue( wxVariant& value,
+ wxPGValidationInfo& validationInfo ) const;
+
+ /**
+ Converts text into wxVariant value appropriate for this property.
+
+ @param variant
+ On function entry this is the old value (should not be wxNullVariant
+ in normal cases). Translated value must be assigned back to it.
+
+ @param text
+ Text to be translated into variant.
+
+ @param argFlags
+ If wxPG_FULL_VALUE is set, returns complete, storable value instead
+ of displayable one (they may be different).
+ If wxPG_COMPOSITE_FRAGMENT is set, text is interpreted as a part of
+ composite property string value (as generated by ValueToString()
+ called with this same flag).
+
+ @return Returns @true if resulting wxVariant value was different.
+
+ @remarks Default implementation converts semicolon delimited tokens into
+ child values. Only works for properties with children.
+
+ You might want to take into account that m_value is Null variant
+ if property value is unspecified (which is usually only case if
+ you explicitly enabled that sort behaviour).
+ */
+ virtual bool StringToValue( wxVariant& variant,
+ const wxString& text,
+ int argFlags = 0 ) const;
+
+ /**
+ Converts integer (possibly a choice selection) into wxVariant value
+ appropriate for this property.
+
+ @param variant
+ On function entry this is the old value (should not be wxNullVariant
+ in normal cases). Translated value must be assigned back to it.
+
+ @param number
+ Integer to be translated into variant.
+
+ @param argFlags
+ If wxPG_FULL_VALUE is set, returns complete, storable value instead
+ of displayable one.
+
+ @return Returns @true if resulting wxVariant value was different.
+
+ @remarks
+ - If property is not supposed to use choice or spinctrl or other editor
+ with int-based value, it is not necessary to implement this method.
+ - Default implementation simply assign given int to m_value.
+ - If property uses choice control, and displays a dialog on some choice
+ items, then it is preferred to display that dialog in IntToValue
+ instead of OnEvent.
+ - You might want to take into account that m_value is Null variant if
+ property value is unspecified (which is usually only case if you
+ explicitly enabled that sort behaviour).
+ */
+ virtual bool IntToValue( wxVariant& value,
+ int number,
+ int argFlags = 0 ) const;
+
+ /**
+ Converts property value into a text representation.
+
+ @param value
+ Value to be converted.