+ /** 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->m_refCount++;
+ }
+ }
+
+ /**
+ Constructor.
+
+ @param labels
+ Labels for choices
+
+ @param values
+ Values for choices. If NULL, indexes are used.
+ */
+ wxPGChoices( const wxChar** 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->m_refCount++;
+ }
+
+ /** 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** 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);
+
+#ifndef SWIG
+ /** Does not create copies for itself. */
+ void Set( const wxChar** labels, const long* values = NULL )
+ {
+ Free();
+ Add(labels,values);
+ }
+#endif // SWIG
+
+ /** 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->m_refCount != 0xFFFFFFF );
+ m_data->m_refCount++;
+ 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;
+
+#ifndef SWIG
+ 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();
+#endif // !SWIG
+};
+
+// -----------------------------------------------------------------------
+
+/** @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
+#ifndef SWIG
+ DECLARE_ABSTRACT_CLASS(wxPGProperty)
+#endif
+public:
+ typedef wxUint32 FlagType;
+
+ /** Basic constructor.
+ */
+ wxPGProperty();
+
+ /** Constructor.
+ Non-abstract property classes should have constructor of this style:
+
+ @code
+
+ // If T is a class, then it should be a constant reference
+ // (e.g. const T& ) instead.
+ MyProperty( const wxString& label, const wxString& name, T value )
+ : wxPGProperty()
+ {
+ // Generally recommended way to set the initial value
+ // (as it should work in pretty much 100% of cases).
+ wxVariant variant;
+ variant << value;
+ SetValue(variant);
+
+ // If has private child properties then create them here. Also
+ // set flag that indicates presence of private children. E.g.:
+ //
+ // AddPrivateChild( new wxStringProperty("Subprop 1",
+ // wxPG_LABEL,
+ // value.GetSubProp1() ) );
+ }
+
+ @endcode
+ */
+ 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; }
+
+#if !defined(SWIG) || defined(CREATE_VCW)
+ /** 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 behavior).
+ */
+ 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 behavior).
+ */
+ virtual bool IntToValue( wxVariant& value,
+ int number,
+ int argFlags = 0 ) const;
+#endif // !defined(SWIG) || defined(CREATE_VCW)
+ /**
+ Converts property value into a text representation.
+
+ @param value
+ Value to be converted.
+
+ @param argFlags
+ If 0 (default value), then displayed string is returned.
+ If wxPG_FULL_VALUE is set, returns complete, storable string value
+ instead of displayable. If wxPG_EDITABLE_VALUE is set, returns
+ string value that must be editable in textctrl. If
+ wxPG_COMPOSITE_FRAGMENT is set, returns text that is appropriate to
+ display as a part of string property's composite text
+ representation.
+
+ @remarks Default implementation calls GenerateComposedValue().
+ */
+ virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
+
+ /** Converts string to a value, and if successful, calls SetValue() on it.
+ Default behavior is to do nothing.
+ @param text
+ String to get the value from.
+ @return
+ true if value was changed.
+ */
+ bool SetValueFromString( const wxString& text, int flags = wxPG_PROGRAMMATIC_VALUE );
+
+ /** Converts integer to a value, and if succesful, calls SetValue() on it.
+ Default behavior is to do nothing.
+ @param value
+ Int to get the value from.
+ @param flags
+ If has wxPG_FULL_VALUE, then the value given is a actual value and
+ not an index.
+ @return
+ True if value was changed.
+ */
+ bool SetValueFromInt( long value, int flags = 0 );
+
+ /**
+ Returns size of the custom painted image in front of property.
+
+ This method must be overridden to return non-default value if
+ OnCustomPaint is to be called.
+ @param item
+ Normally -1, but can be an index to the property's list of items.
+ @remarks
+ - Default behavior is to return wxSize(0,0), which means no image.
+ - Default image width or height is indicated with dimension -1.
+ - You can also return wxPG_DEFAULT_IMAGE_SIZE, i.e. wxSize(-1, -1).
+ */
+ virtual wxSize OnMeasureImage( int item = -1 ) const;
+
+ /**
+ Events received by editor widgets are processed here.