// Author: Jaakko Salli
// Modified by:
// Created: 2008-08-23
-// RCS-ID: $Id:
+// RCS-ID: $Id$
// Copyright: (c) Jaakko Salli
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PROPGRID_PROPERTY_H_
#define _WX_PROPGRID_PROPERTY_H_
+#include "wx/defs.h"
+
#if wxUSE_PROPGRID
#include "wx/propgrid/propgriddefs.h"
};
-// Structure for relaying choice/list info.
-struct wxPGChoiceInfo
-{
- wxPGChoices* m_choices;
-};
-
-
-#ifndef SWIG
-
-
// space between vertical sides of a custom image
#define wxPG_CUSTOM_IMAGE_SPACINGY 1
Base class for wxPropertyGrid cell renderers.
*/
-class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
+class WXDLLIMPEXP_PROPGRID wxPGCellRenderer : public wxObjectRefData
{
public:
- wxPGCellRenderer( unsigned int refCount = 1 )
- : m_refCount(refCount) { }
+ wxPGCellRenderer()
+ : wxObjectRefData() { }
virtual ~wxPGCellRenderer() { }
// Render flags
enum
{
+ // We are painting selected item
Selected = 0x00010000,
- Control = 0x00020000
+
+ // We are painting item in choice popup
+ ChoicePopup = 0x00020000,
+
+ // We are rendering wxOwnerDrawnComboBox control
+ // (or other owner drawn control, but that is only
+ // officially supported one ATM).
+ Control = 0x00040000,
+
+ // We are painting a disable property
+ Disabled = 0x00080000,
+
+ // We are painting selected, disabled, or similar
+ // item that dictates fore- and background colours,
+ // overriding any cell values.
+ DontUseCellFgCol = 0x00100000,
+ DontUseCellBgCol = 0x00200000,
+ DontUseCellColours = DontUseCellFgCol |
+ DontUseCellBgCol
};
- virtual void Render( wxDC& dc,
+ /**
+ Returns @true if rendered something in the foreground (text or
+ bitmap.
+ */
+ virtual bool Render( wxDC& dc,
const wxRect& rect,
const wxPropertyGrid* propertyGrid,
wxPGProperty* property,
wxPGProperty* property,
const wxPGEditor* editor ) const;
- /** Utility to render cell bitmap and set text colour plus bg brush colour.
+ /** Utility to render cell bitmap and set text colour plus bg brush
+ colour.
- Returns image width that, for instance, can be passed to DrawText.
+ @return Returns image width, which, for instance, can be passed to
+ DrawText.
*/
int PreDrawCell( wxDC& dc,
const wxRect& rect,
const wxPGCell& cell,
int flags ) const;
- void IncRef()
- {
- m_refCount++;
- }
-
- void DecRef()
- {
- m_refCount--;
- if ( !m_refCount )
- delete this;
- }
-protected:
+ /**
+ Utility to be called after drawing is done, to revert whatever
+ changes PreDrawCell() did.
-private:
- unsigned int m_refCount;
+ @param flags
+ Same as those passed to PreDrawCell().
+ */
+ void PostDrawCell( wxDC& dc,
+ const wxPropertyGrid* propGrid,
+ const wxPGCell& cell,
+ int flags ) const;
};
-/** @class wxPGCell
+/**
+ @class wxPGDefaultRenderer
- Base class for simple wxPropertyGrid cell information.
+ Default cell renderer, that can handles the common
+ scenarios.
*/
-class WXDLLIMPEXP_PROPGRID wxPGCell
+class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
{
public:
- wxPGCell();
- wxPGCell( const wxString& text,
- const wxBitmap& bitmap = wxNullBitmap,
- const wxColour& fgCol = wxNullColour,
- const wxColour& bgCol = wxNullColour );
+ virtual bool Render( wxDC& dc,
+ const wxRect& rect,
+ const wxPropertyGrid* propertyGrid,
+ wxPGProperty* property,
+ int column,
+ int item,
+ int flags ) const;
- virtual ~wxPGCell() { }
+ virtual wxSize GetImageSize( const wxPGProperty* property,
+ int column,
+ int item ) const;
+
+protected:
+};
+
+
+class WXDLLIMPEXP_PROPGRID wxPGCellData : public wxObjectRefData
+{
+ friend class wxPGCell;
+public:
+ wxPGCellData();
- void SetText( const wxString& text ) { m_text = text; }
+ void SetText( const wxString& text )
+ {
+ m_text = text;
+ m_hasValidText = true;
+ }
void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
void SetFgCol( const wxColour& col ) { m_fgCol = col; }
void SetBgCol( const wxColour& col ) { m_bgCol = col; }
-
- const wxString& GetText() const { return m_text; }
- const wxBitmap& GetBitmap() const { return m_bitmap; }
- const wxColour& GetFgCol() const { return m_fgCol; }
- const wxColour& GetBgCol() const { return m_bgCol; }
+ void SetFont( const wxFont& font ) { m_font = font; }
protected:
+ virtual ~wxPGCellData() { }
+
wxString m_text;
wxBitmap m_bitmap;
wxColour m_fgCol;
wxColour m_bgCol;
+ wxFont m_font;
+
+ // True if m_text is valid and specified
+ bool m_hasValidText;
};
-/** @class wxPGDefaultRenderer
+/**
+ @class wxPGCell
- Default cell renderer, that can handles the common
- scenarios.
+ Base class for wxPropertyGrid cell information.
*/
-class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer
+class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject
{
public:
- virtual void Render( wxDC& dc,
- const wxRect& rect,
- const wxPropertyGrid* propertyGrid,
- wxPGProperty* property,
- int column,
- int item,
- int flags ) const;
+ wxPGCell();
+ wxPGCell(const wxPGCell& other)
+ : wxObject(other)
+ {
+ }
- virtual wxSize GetImageSize( const wxPGProperty* property,
- int column,
- int item ) const;
+ wxPGCell( const wxString& text,
+ const wxBitmap& bitmap = wxNullBitmap,
+ const wxColour& fgCol = wxNullColour,
+ const wxColour& bgCol = wxNullColour );
-protected:
+ virtual ~wxPGCell() { }
+
+ wxPGCellData* GetData()
+ {
+ return (wxPGCellData*) m_refData;
+ }
+
+ const wxPGCellData* GetData() const
+ {
+ return (const wxPGCellData*) m_refData;
+ }
+
+ bool HasText() const
+ {
+ return (m_refData && GetData()->m_hasValidText);
+ }
+
+ /**
+ Sets empty but valid data to this cell object.
+ */
+ void SetEmptyData();
+
+ /**
+ Merges valid data from srcCell into this.
+ */
+ void MergeFrom( const wxPGCell& srcCell );
+
+ void SetText( const wxString& text );
+ void SetBitmap( const wxBitmap& bitmap );
+ void SetFgCol( const wxColour& col );
+
+ /**
+ Sets font of the cell.
+
+ @remarks Because wxPropertyGrid does not support rows of
+ different height, it makes little sense to change
+ size of the font. Therefore it is recommended
+ to use return value of wxPropertyGrid::GetFont()
+ or wxPropertyGrid::GetCaptionFont() as a basis
+ for the font that, after modifications, is passed
+ to this member function.
+ */
+ void SetFont( const wxFont& font );
+
+ void SetBgCol( const wxColour& col );
+
+ const wxString& GetText() const { return GetData()->m_text; }
+ const wxBitmap& GetBitmap() const { return GetData()->m_bitmap; }
+ const wxColour& GetFgCol() const { return GetData()->m_fgCol; }
+
+ /**
+ Returns font of the cell. If no specific font is set for this
+ cell, then the font will be invalid.
+ */
+ const wxFont& GetFont() const { return GetData()->m_font; }
+
+ const wxColour& GetBgCol() const { return GetData()->m_bgCol; }
+
+ wxPGCell& operator=( const wxPGCell& other )
+ {
+ if ( this != &other )
+ {
+ Ref(other);
+ }
+ return *this;
+ }
+
+ // Used mostly internally to figure out if this cell is supposed
+ // to have default values when attached to a grid.
+ bool IsInvalid() const
+ {
+ return ( m_refData == NULL );
+ }
+
+private:
+ virtual wxObjectRefData *CreateRefData() const
+ { return new wxPGCellData(); }
+
+ virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
};
// -----------------------------------------------------------------------
~wxPGAttributeStorage();
void Set( const wxString& name, const wxVariant& value );
- size_t GetCount() const { return m_map.size(); }
+ unsigned int GetCount() const { return (unsigned int) m_map.size(); }
wxVariant FindValue( const wxString& name ) const
{
wxPGHashMapS2P::const_iterator it = m_map.find(name);
data->IncRef();
variant.SetData(data);
variant.SetName(it->first);
- it++;
+ ++it;
return true;
}
wxPGHashMapS2P m_map;
};
-#endif // !SWIG
// -----------------------------------------------------------------------
@{
*/
-enum wxPG_PROPERTY_FLAGS
+enum wxPGPropertyFlags
{
/** Indicates bold font.
If property is selected, then indicates that validation failed for pending
value.
- If property is not selected, then indicates that the the actual property
- value has failed validation (NB: this behavior is not currently supported,
+ If property is not selected, that indicates that the actual property
+ value has failed validation (NB: this behaviour is not currently supported,
but may be used in future).
*/
wxPG_PROP_INVALID_VALUE = 0x0040,
*/
wxPG_PROP_MISC_PARENT = 0x4000,
-/** Property is read-only. Editor is still created.
+/** Property is read-only. Editor is still created for wxTextCtrl-based
+ property editors. For others, editor is not usually created because
+ they do implement wxTE_READONLY style or equivalent.
*/
wxPG_PROP_READONLY = 0x8000,
@remarks
This flag cannot be used with property iterators.
+
+ @see wxPGProperty::SetAutoUnspecified()
*/
wxPG_PROP_AUTO_UNSPECIFIED = 0x00040000,
/** Indicates the bit useable by derived properties.
*/
-wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000
+wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000,
+
+/** Indicates that the property is being deleted and should be ignored.
+*/
+wxPG_PROP_BEING_DELETED = 0x00200000
};
Code should automatically take care of this, however.
*/
#define wxPG_PROP_PARENTAL_FLAGS \
- (wxPG_PROP_AGGREGATE|wxPG_PROP_CATEGORY|wxPG_PROP_MISC_PARENT)
+ ((wxPGPropertyFlags)(wxPG_PROP_AGGREGATE | \
+ wxPG_PROP_CATEGORY | \
+ wxPG_PROP_MISC_PARENT))
/** @}
*/
-// Amalgam of flags that should be inherited by sub-properties
-#define wxPG_INHERITED_PROPFLAGS (wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR)
-
// Combination of flags that can be stored by GetFlagsAsString
#define wxPG_STRING_STORED_FLAGS \
(wxPG_PROP_DISABLED|wxPG_PROP_HIDDEN|wxPG_PROP_NOEDITOR|wxPG_PROP_COLLAPSED)
// -----------------------------------------------------------------------
-#ifndef SWIG
-
/**
@section propgrid_property_attributes wxPropertyGrid Property Attribute
Identifiers.
*/
#define wxPG_ATTR_UNITS wxS("Units")
-/** Universal, string. When set, will be shown in property's value cell
- when displayed value string is empty, or value is unspecified.
+/** When set, will be shown as 'greyed' text in property's value cell when
+ the actual displayed value is blank.
+*/
+#define wxPG_ATTR_HINT wxS("Hint")
+
+#if wxPG_COMPATIBILITY_1_4
+/**
+ @deprecated Use "Hint" (wxPG_ATTR_HINT) instead.
*/
#define wxPG_ATTR_INLINE_HELP wxS("InlineHelp")
+#endif
+
+/** Universal, wxArrayString. Set to enable auto-completion in any
+ wxTextCtrl-based property editor.
+*/
+#define wxPG_ATTR_AUTOCOMPLETE wxS("AutoComplete")
-/** wxBoolProperty specific, int, default 0. When 1 sets bool property to
- use checkbox instead of choice.
+/** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
+ Default value is False.
+
+ When set to True, bool property will use check box instead of a
+ combo box as its editor control. If you set this attribute
+ for a wxFlagsProperty, it is automatically applied to child
+ bool properties.
*/
#define wxPG_BOOL_USE_CHECKBOX wxS("UseCheckbox")
-/** wxBoolProperty specific, int, default 0. When 1 sets bool property value
- to cycle on double click (instead of showing the popup listbox).
+/** wxBoolProperty and wxFlagsProperty specific. Value type is bool.
+ Default value is False.
+
+ Set to True for the bool property to cycle value on double click
+ (instead of showing the popup listbox). If you set this attribute
+ for a wxFlagsProperty, it is automatically applied to child
+ bool properties.
*/
#define wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING wxS("UseDClickCycling")
*/
#define wxPG_FILE_DIALOG_TITLE wxS("DialogTitle")
+/** Specific to wxFileProperty and derivatives, long, default is 0.
+ Sets a specific wxFileDialog style for the file dialog.
+*/
+#define wxPG_FILE_DIALOG_STYLE wxS("DialogStyle")
+
/** Specific to wxDirProperty, wxString, default is empty.
Sets a specific message for the dir dialog.
*/
#define wxPG_DIR_DIALOG_MESSAGE wxS("DialogMessage")
+/**
+ wxArrayStringProperty's string delimiter character. If this is a quotation
+ mark or hyphen, then strings will be quoted instead (with given
+ character).
+
+ Default delimiter is quotation mark.
+*/
+#define wxPG_ARRAY_DELIMITER wxS("Delimiter")
+
/** Sets displayed date format for wxDateProperty.
*/
#define wxPG_DATE_FORMAT wxS("DateFormat")
#define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
/** SpinCtrl editor, int or double. How much number changes when button is
- pressed (or up/down on keybard).
+ pressed (or up/down on keyboard).
*/
#define wxPG_ATTR_SPINCTRL_STEP wxS("Step")
*/
#define wxPG_COLOUR_ALLOW_CUSTOM wxS("AllowCustom")
+/**
+ wxColourProperty and its kind: Set to True in order to support editing
+ alpha colour component.
+*/
+#define wxPG_COLOUR_HAS_ALPHA wxS("HasAlpha")
+
/** @}
*/
// Redefine attribute macros to use cached strings
+#undef wxPG_ATTR_DEFAULT_VALUE
+#define wxPG_ATTR_DEFAULT_VALUE wxPGGlobalVars->m_strDefaultValue
#undef wxPG_ATTR_MIN
#define wxPG_ATTR_MIN wxPGGlobalVars->m_strMin
#undef wxPG_ATTR_MAX
#define wxPG_ATTR_MAX wxPGGlobalVars->m_strMax
#undef wxPG_ATTR_UNITS
#define wxPG_ATTR_UNITS wxPGGlobalVars->m_strUnits
+#undef wxPG_ATTR_HINT
+#define wxPG_ATTR_HINT wxPGGlobalVars->m_strHint
+#if wxPG_COMPATIBILITY_1_4
#undef wxPG_ATTR_INLINE_HELP
#define wxPG_ATTR_INLINE_HELP wxPGGlobalVars->m_strInlineHelp
-
-#endif // !SWIG
+#endif
// -----------------------------------------------------------------------
-/** @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 wxPGChoiceEntry
+ Data of a single wxPGChoices choice.
*/
-class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject
+class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
{
- 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();
+ wxPGChoiceEntry();
+ wxPGChoiceEntry(const wxPGChoiceEntry& other)
+ : wxPGCell(other)
+ {
+ m_value = other.m_value;
+ }
+ wxPGChoiceEntry( const wxString& label,
+ int value = wxPG_INVALID_VALUE )
+ : wxPGCell(), m_value(value)
+ {
+ SetText(label);
+ }
- /** Constructor.
- Non-abstract property classes should have constructor of this style:
+ virtual ~wxPGChoiceEntry() { }
- @code
+ void SetValue( int value ) { m_value = value; }
+ int GetValue() const { return m_value; }
- // 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()
+ wxPGChoiceEntry& operator=( const wxPGChoiceEntry& other )
+ {
+ if ( this != &other )
{
- // 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, e.g.:
- // AddChild( new wxStringProperty( "Subprop 1",
- // wxPG_LABEL,
- // value.GetSubProp1() ) );
+ Ref(other);
}
+ m_value = other.m_value;
+ return *this;
+ }
- @endcode
- */
- wxPGProperty( const wxString& label, const wxString& name );
+protected:
+ int m_value;
+};
- /**
- Virtual destructor.
- It is customary for derived properties to implement this.
- */
- virtual ~wxPGProperty();
- /** This virtual function is called after m_value has been set.
+typedef void* wxPGChoicesId;
- @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();
+class WXDLLIMPEXP_PROPGRID wxPGChoicesData : public wxObjectRefData
+{
+ friend class wxPGChoices;
+public:
+ // Constructor sets m_refCount to 1.
+ wxPGChoicesData();
- /** Override this to return something else than m_value as the value.
- */
- virtual wxVariant DoGetValue() const { return m_value; }
+ void CopyDataFrom( wxPGChoicesData* data );
-#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.
+ wxPGChoiceEntry& Insert( int index, const wxPGChoiceEntry& item );
- @remarks
- - Default implementation always returns true.
- */
- virtual bool ValidateValue( wxVariant& value,
- wxPGValidationInfo& validationInfo ) const;
+ // Delete all entries
+ void Clear();
- /**
- Converts 'text' into proper value 'variant'.
- Returns true if new (different than m_value) value could be interpreted
- from the text.
- @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 GetValueAsString()
- called with this same flag).
+ unsigned int GetCount() const
+ {
+ return (unsigned int) m_items.size();
+ }
- @remarks
- Default implementation converts semicolon delimited tokens into child
- values. Only works for properties with children.
- */
- virtual bool StringToValue( wxVariant& variant,
- const wxString& text,
- int argFlags = 0 ) const;
+ const wxPGChoiceEntry& Item( unsigned int i ) const
+ {
+ wxASSERT_MSG( i < GetCount(), "invalid index" );
+ return m_items[i];
+ }
- /**
- Converts 'number' (including choice selection) into proper value
- 'variant'.
+ wxPGChoiceEntry& Item( unsigned int i )
+ {
+ wxASSERT_MSG( i < GetCount(), "invalid index" );
+ return m_items[i];
+ }
- Returns true if new (different than m_value) value could be interpreted
- from the integer.
+private:
+ wxVector<wxPGChoiceEntry> m_items;
- @param argFlags
- If wxPG_FULL_VALUE is set, returns complete, storable value instead
- of displayable one.
+ virtual ~wxPGChoicesData();
+};
- @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.
- */
- virtual bool IntToValue( wxVariant& value,
- int number,
- int argFlags = 0 ) const;
-#endif // !defined(SWIG) || defined(CREATE_VCW)
+#define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
-public:
- /** Returns text representation of property's value.
+
+/** @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.
@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 composite property string value.
+ display as a part of string property's composite text
+ representation.
- @remarks
- Default implementation returns string composed from text
- representations of child properties.
+ @remarks Default implementation calls GenerateComposedValue().
*/
- virtual wxString GetValueAsString( int argFlags = 0 ) const;
+ 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.
+ Default behaviour 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 = 0 );
+ 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.
+ /** Converts integer to a value, and if successful, calls SetValue() on it.
+ Default behaviour is to do nothing.
@param value
Int to get the value from.
@param flags
@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 behaviour 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).
*/
wxEvent& event );
/**
- Called after value of a child property has been altered.
+ Called after value of a child property has been altered. Must return
+ new value of the whole property (after any alterations warranted by
+ child's new value).
Note that this function is usually called at the time that value of
- this property, or given child property, is still pending for change.
+ this property, or given child property, is still pending for change,
+ and as such, result of GetValue() or m_value should not be relied
+ on.
Sample pseudo-code implementation:
@code
- void MyProperty::ChildChanged( wxVariant& thisValue,
- int childIndex,
- wxVariant& childValue ) const
+ wxVariant MyProperty::ChildChanged( wxVariant& thisValue,
+ int childIndex,
+ wxVariant& childValue ) const
{
// Acquire reference to actual type of data stored in variant
// (TFromVariant only exists if wxPropertyGrid's wxVariant-macros
break;
...
}
+
+ // Return altered data
+ return data;
}
@endcode
@param thisValue
- Value of this property, that should be altered.
+ Value of this property. Changed value should be returned (in
+ previous versions of wxPropertyGrid it was only necessary to
+ write value back to this argument).
@param childIndex
- Index of child changed (you can use Item(childIndex) to get).
+ Index of child changed (you can use Item(childIndex) to get
+ child property).
@param childValue
- Value of the child property.
+ (Pending) value of the child property.
+
+ @return
+ Modified value of the whole property.
*/
- virtual void ChildChanged( wxVariant& thisValue,
- int childIndex,
- wxVariant& childValue ) const;
+ virtual wxVariant ChildChanged( wxVariant& thisValue,
+ int childIndex,
+ wxVariant& childValue ) const;
/** Returns pointer to an instance of used editor.
*/
*/
virtual wxValidator* DoGetValidator () const;
- /**
- Returns current value's index to the choice control.
-
- May also return, through pointer arguments, strings that should be
- inserted to that control. Irrelevant to classes which do not employ
- wxPGEditor_Choice or similar.
-
- @remarks
- - If returns NULL in choiceinfo.m_choices, then this class must be
- derived from wxBaseEnumProperty.
- - Must be able to cope situation where property's set of choices is
- uninitialized.
- */
- virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
-
/**
Override to paint an image in front of the property value text or
drop-down list item (but only if wxPGProperty::OnMeasureImage is
colour) pen for drawing framing rectangle. It can be changed as
well.
- @see GetValueAsString()
+ @see ValueToString()
*/
virtual void OnCustomPaint( wxDC& dc,
const wxRect& rect,
*/
virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
+ /** Returns which choice is currently selected. Only applies to properties
+ which have choices.
+
+ Needs to reimplemented in derived class if property value does not
+ map directly to a choice. Integer as index, bool, and string usually do.
+ */
+ virtual int GetChoiceSelection() const;
+
/**
Refresh values of child properties.
*/
virtual void RefreshChildren();
- /** Special handling for attributes of this property.
+ /**
+ Reimplement this member function to add special handling for
+ attributes of this property.
- If returns false, then the attribute will be automatically stored in
- m_attributes.
+ @return Return @false to have the attribute automatically stored in
+ m_attributes. Default implementation simply does that and
+ nothing else.
- Default implementation simply returns false.
+ @remarks To actually set property attribute values from the
+ application, use wxPGProperty::SetAttribute() instead.
*/
virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
/**
- Adds entry to property's wxPGChoices and editor control (if it is
- active).
+ Called whenever validation has failed with given pending value.
- Returns index of item added.
+ @remarks If you implement this in your custom property class, please
+ remember to call the baser implementation as well, since they
+ may use it to revert property into pre-change state.
*/
- int AppendChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
- {
- return InsertChoice(label,-1,value);
- }
+ virtual void OnValidationFailure( wxVariant& pendingValue );
- /** Returns wxPGCell of given column, NULL if none. If valid
- object is returned, caller will gain its ownership.
+ /** Append a new choice to property's list of choices.
*/
- wxPGCell* AcquireCell( unsigned int column )
+ int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
{
- if ( column >= m_cells.size() )
- return NULL;
-
- wxPGCell* cell = (wxPGCell*) m_cells[column];
- m_cells[column] = NULL;
- return cell;
+ return InsertChoice(label, wxNOT_FOUND, value);
}
/**
return false;
}
+ /**
+ Deletes children of the property.
+ */
+ void DeleteChildren();
+
/**
Removes entry from property's wxPGChoices and editor control (if it is
active).
*/
void DeleteChoice( int index );
+ /**
+ Enables or disables the property. Disabled property usually appears
+ as having grey text.
+
+ @param enable
+ If @false, property is disabled instead.
+
+ @see wxPropertyGridInterface::EnableProperty()
+ */
+ void Enable( bool enable = true );
+
/**
Call to enable or disable usage of common value (integer value that can
be selected for properties instead of their normal values) for this
else ClearFlag( wxPG_PROP_USES_COMMON_VALUE );
}
- /** Composes text from values of child properties. */
- void GenerateComposedValue( wxString& text, int argFlags = 0 ) const;
+ /**
+ Composes text from values of child properties.
+ */
+ wxString GenerateComposedValue() const
+ {
+ wxString s;
+ DoGenerateComposedValue(s);
+ return s;
+ }
/** Returns property's label. */
const wxString& GetLabel() const { return m_label; }
*/
const wxString& GetBaseName() const { return m_name; }
- wxPGChoices& GetChoices();
-
- const wxPGChoices& GetChoices() const;
-
- const wxPGChoiceEntry* GetCurrentChoice() const;
+ /** Returns read-only reference to property's list of choices.
+ */
+ const wxPGChoices& GetChoices() const
+ {
+ return m_choices;
+ }
/** Returns coordinate to the top y of the property. Note that the
position of scrollbars is not taken into account.
return DoGetValue();
}
-#ifndef SWIG
/** Returns reference to the internal stored value. GetValue is preferred
way to get the actual value, since GetValueRef ignores DoGetValue,
which may override stored value.
{
return m_value;
}
-#endif
- /** Same as GetValueAsString, except takes common value into account.
+ // Helper function (for wxPython bindings and such) for settings protected
+ // m_value.
+ wxVariant GetValuePlain() const
+ {
+ return m_value;
+ }
+
+ /** Returns text representation of property's value.
+
+ @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 In older versions, this function used to be overridden to convert
+ property's value into a string representation. This function is
+ now handled by ValueToString(), and overriding this function now
+ will result in run-time assertion failure.
*/
- wxString GetValueString( int argFlags = 0 ) const;
+ virtual wxString GetValueAsString( int argFlags = 0 ) const;
+
+ /** Synonymous to GetValueAsString().
- void UpdateControl( wxWindow* primary );
+ @deprecated Use GetValueAsString() instead.
- /** Returns wxPGCell of given column, NULL if none. wxPGProperty
- will retain ownership of the cell object.
+ @see GetValueAsString()
*/
- wxPGCell* GetCell( unsigned int column ) const
- {
- if ( column >= m_cells.size() )
- return NULL;
+ wxDEPRECATED( wxString GetValueString( int argFlags = 0 ) const );
- return (wxPGCell*) m_cells[column];
- }
+ /**
+ Returns wxPGCell of given column.
- unsigned int GetChoiceCount() const;
+ @remarks const version of this member function returns 'default'
+ wxPGCell object if the property itself didn't hold
+ cell data.
+ */
+ const wxPGCell& GetCell( unsigned int column ) const;
+
+ /**
+ Returns wxPGCell of given column, creating one if necessary.
+ */
+ wxPGCell& GetCell( unsigned int column )
+ {
+ return GetOrCreateCell(column);
+ }
- wxString GetChoiceString( unsigned int index );
+ /**
+ Returns wxPGCell of given column, creating one if necessary.
+ */
+ wxPGCell& GetOrCreateCell( unsigned int column );
/** Return number of displayed common values for this property.
*/
wxString GetDisplayedString() const
{
- return GetValueString(0);
+ return GetValueAsString(0);
}
+ /**
+ Returns property's hint text (shown in empty value cell).
+ */
+ inline wxString GetHintText() const;
+
/** Returns property grid where property lies. */
wxPropertyGrid* GetGrid() const;
/** Returns true if property has editable wxTextCtrl when selected.
@remarks
- Altough disabled properties do not displayed editor, they still
+ Although disabled properties do not displayed editor, they still
return True here as being disabled is considered a temporary
condition (unlike being read-only or having limited editing enabled).
*/
return m_value.IsNull();
}
- FlagType HasFlag( FlagType flag ) const
+ /**
+ Returns non-zero if property has given flag set.
+
+ @see propgrid_propflags
+ */
+ FlagType HasFlag( wxPGPropertyFlags flag ) const
{
return ( m_flags & flag );
}
*/
wxVariant GetAttributesAsList() const;
+ /**
+ Returns property flags.
+ */
FlagType GetFlags() const
{
return m_flags;
bool HasVisibleChildren() const;
/**
- Adds entry to property's wxPGChoices and editor control (if it is
- active).
+ Use this member function to add independent (ie. regular) children to
+ a property.
+
+ @return Inserted childProperty.
- Returns index of item added.
+ @remarks wxPropertyGrid is not automatically refreshed by this
+ function.
+
+ @see AddPrivateChild()
+ */
+ wxPGProperty* InsertChild( int index, wxPGProperty* childProperty );
+
+ /** Inserts a new choice to property's list of choices.
*/
- int InsertChoice( const wxString& label,
- int index,
- int value = wxPG_INVALID_VALUE );
+ int InsertChoice( const wxString& label, int index, int value = wxPG_INVALID_VALUE );
/**
Returns true if this property is actually a wxPropertyCategory.
/**
Determines, recursively, if all children are not unspecified.
- Takes values in given list into account.
+ @param pendingList
+ Assumes members in this wxVariant list as pending
+ replacement values.
*/
bool AreAllChildrenSpecified( wxVariant* pendingList = NULL ) const;
/** Returns true if containing grid uses wxPG_EX_AUTO_UNSPECIFIED_VALUES.
*/
- FlagType UsesAutoUnspecified() const
+ bool UsesAutoUnspecified() const
{
- return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED);
+ return HasFlag(wxPG_PROP_AUTO_UNSPECIFIED)?true:false;
}
wxBitmap* GetValueImage() const
*/
double GetAttributeAsDouble( const wxString& name, double defVal ) const;
- unsigned int GetArrIndex() const { return m_arrIndex; }
-
unsigned int GetDepth() const { return (unsigned int)m_depth; }
/** Gets flags as a'|' delimited string. Note that flag names are not
By default changes are applied recursively. Set this paramter
wxPG_DONT_RECURSE to prevent this.
*/
- inline bool Hide( bool hide, int flags = wxPG_RECURSE );
+ bool Hide( bool hide, int flags = wxPG_RECURSE );
bool IsExpanded() const
{ return (!(m_flags & wxPG_PROP_COLLAPSED) && GetChildCount()); }
*/
void RefreshEditor();
- /** Sets an attribute for this property.
- @param name
- Text identifier of attribute. See @ref propgrid_property_attributes.
- @param value
- Value of attribute.
+ /** Sets an attribute for this property.
+ @param name
+ Text identifier of attribute. See @ref propgrid_property_attributes.
+ @param value
+ Value of attribute.
+ */
+ void SetAttribute( const wxString& name, wxVariant value );
+
+ void SetAttributes( const wxPGAttributeStorage& attributes );
+
+ /**
+ Set if user can change the property's value to unspecified by
+ modifying the value of the editor control (usually by clearing
+ it). Currently, this can work with following properties:
+ wxIntProperty, wxUIntProperty, wxFloatProperty, wxEditEnumProperty.
+
+ @param enable
+ Whether to enable or disable this behaviour (it is disabled by
+ default).
+ */
+ void SetAutoUnspecified( bool enable = true )
+ {
+ ChangeFlag(wxPG_PROP_AUTO_UNSPECIFIED, enable);
+ }
+
+ /**
+ Sets property's background colour.
+
+ @param colour
+ Background colour to use.
+
+ @param flags
+ Default is wxPG_RECURSE which causes colour to be set recursively.
+ Omit this flag to only set colour for the property in question
+ and not any of its children.
+ */
+ void SetBackgroundColour( const wxColour& colour,
+ int flags = wxPG_RECURSE );
+
+ /**
+ Sets property's text colour.
+
+ @param colour
+ Text colour to use.
+
+ @param flags
+ Default is wxPG_RECURSE which causes colour to be set recursively.
+ Omit this flag to only set colour for the property in question
+ and not any of its children.
*/
- void SetAttribute( const wxString& name, wxVariant value );
+ void SetTextColour( const wxColour& colour,
+ int flags = wxPG_RECURSE );
- void SetAttributes( const wxPGAttributeStorage& attributes );
+ /** Set default value of a property. Synonymous to
+
+ @code
+ SetAttribute("DefaultValue", value);
+ @endcode
+ */
+ void SetDefaultValue( wxVariant& value );
-#ifndef SWIG
/** Sets editor for a property.
@param editor
{
m_customEditor = editor;
}
-#endif
/** Sets editor for a property.
*/
inline void SetEditor( const wxString& editorName );
- /** Sets cell information for given column.
-
- Note that the property takes ownership of given wxPGCell instance.
+ /**
+ Sets cell information for given column.
*/
- void SetCell( int column, wxPGCell* cellObj );
-
- /** Changes value of a property with choices, but only
- works if the value type is long or string. */
- void SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo );
+ void SetCell( int column, const wxPGCell& cell );
/** Sets common value selected for this property. -1 for none.
*/
SetValueInEvent() instead.
@param pList
- Pointer to list variant that contains child values. Used to indicate
- which children should be marked as modified.
+ Pointer to list variant that contains child values. Used to
+ indicate which children should be marked as modified.
+
@param flags
- Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR).
+ Various flags (for instance, wxPG_SETVAL_REFRESH_EDITOR, which is
+ enabled by default).
*/
- void SetValue( wxVariant value, wxVariant* pList = NULL, int flags = 0 );
+ void SetValue( wxVariant value, wxVariant* pList = NULL,
+ int flags = wxPG_SETVAL_REFRESH_EDITOR );
/** Set wxBitmap in front of the value. This bitmap may be ignored
by custom cell renderers.
*/
void SetValueImage( wxBitmap& bmp );
- /** If property has choices and they are not yet exclusive, new such copy
- of them will be created.
+ /** Sets selected choice and changes property value.
+
+ Tries to retain value type, although currently if it is not string,
+ then it is forced to integer.
*/
- void SetChoicesExclusive();
+ void SetChoiceSelection( int newValue );
void SetExpanded( bool expanded )
{
else m_flags &= ~wxPG_PROP_COLLAPSED;
}
- void SetFlag( FlagType flag ) { m_flags |= flag; }
-
- void SetFlagRecursively( FlagType flag, bool set );
-
- void SetHelpString( const wxString& helpString )
- {
- m_helpString = helpString;
- }
-
- void SetLabel( const wxString& label ) { m_label = label; }
-
- inline void SetName( const wxString& newName );
-
- void SetValueToUnspecified()
- {
- wxVariant val; // Create NULL variant
- SetValue(val);
- }
-
-#if wxUSE_VALIDATORS
- /** Sets wxValidator for a property*/
- void SetValidator( const wxValidator& validator )
- {
- m_validator = wxDynamicCast(validator.Clone(),wxValidator);
- }
-
- /** Gets assignable version of property's validator. */
- wxValidator* GetValidator() const
- {
- if ( m_validator )
- return m_validator;
- return DoGetValidator();
- }
-#endif // #if wxUSE_VALIDATORS
-
- /** Updates property value in case there were last minute
- changes. If value was unspecified, it will be set to default.
- Use only for properties that have TextCtrl-based editor.
- @remarks
- If you have code similar to
- @code
- // Update the value in case of last minute changes
- if ( primary && propgrid->IsEditorsValueModified() )
- GetEditorClass()->CopyValueFromControl( this, primary );
- @endcode
- in wxPGProperty::OnEvent wxEVT_COMMAND_BUTTON_CLICKED handler,
- then replace it with call to this method.
- @return
- True if value changed.
- */
- bool PrepareValueForDialogEditing( wxPropertyGrid* propgrid );
-
-#ifndef SWIG
- /** Returns client data (void*) of a property.
- */
- void* GetClientData() const
- {
- return m_clientData;
- }
-
- /** Sets client data (void*) of a property.
- @remarks
- This untyped client data has to be deleted manually.
- */
- void SetClientData( void* clientData )
- {
- m_clientData = clientData;
- }
-
- /** Returns client object of a property.
- */
- void SetClientObject(wxClientData* clientObject)
- {
- delete m_clientObject;
- m_clientObject = clientObject;
- }
-
- /** Sets managed client object of a property.
- */
- wxClientData *GetClientObject() const { return m_clientObject; }
-#endif
-
- /** Sets new set of choices for property.
-
- @remarks
- This operation clears the property value.
- */
- bool SetChoices( wxPGChoices& choices );
-
- /** Sets new set of choices for property.
- */
- inline bool SetChoices( const wxArrayString& labels,
- const wxArrayInt& values = wxArrayInt() );
+ /**
+ Sets or clears given property flag. Mainly for internal use.
- /** Set max length of text in text editor.
- */
- inline bool SetMaxLength( int maxLen );
+ @remarks Setting a property flag never has any side-effect, and is
+ intended almost exclusively for internal use. So, for
+ example, if you want to disable a property, call
+ Enable(false) instead of setting wxPG_PROP_DISABLED flag.
- /** Call with 'false' in OnSetValue to cancel value changes after all
- (ie. cancel 'true' returned by StringToValue() or IntToValue()).
+ @see HasFlag(), GetFlags()
*/
- void SetWasModified( bool set = true )
+ void ChangeFlag( wxPGPropertyFlags flag, bool set )
{
- if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
- else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
- }
-
- const wxString& GetHelpString() const
- {
- return m_helpString;
+ if ( set )
+ m_flags |= flag;
+ else
+ m_flags &= ~flag;
}
- void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
-
- // Use, for example, to detect if item is inside collapsed section.
- bool IsSomeParent( wxPGProperty* candidate_parent ) const;
-
/**
- Adapts list variant into proper value using consecutive
- ChildChanged-calls.
- */
- void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
-
- /** This is used by properties that have fixed sub-properties. */
- void AddChild( wxPGProperty* prop );
-
- /** Returns height of children, recursively, and
- by taking expanded/collapsed status into account.
-
- iMax is used when finding property y-positions.
- */
- int GetChildrenHeight( int lh, int iMax = -1 ) const;
-
- /** Returns number of child properties */
- unsigned int GetChildCount() const { return m_children.GetCount(); }
-
- /** Returns sub-property at index i. */
- wxPGProperty* Item( size_t i ) const
- { return (wxPGProperty*)m_children.Item(i); }
-
- /** Returns last sub-property.
- */
- wxPGProperty* Last() const { return (wxPGProperty*)m_children.Last(); }
+ Sets or clears given property flag, recursively. This function is
+ primarily intended for internal use.
- /** Returns index of given sub-property. */
- int Index( const wxPGProperty* p ) const
- { return m_children.Index((wxPGProperty*)p); }
-
- /** Deletes all sub-properties. */
- void Empty();
-
- // Puts correct indexes to children
- void FixIndexesOfChildren( size_t starthere = 0 );
-
-#ifndef SWIG
- // Returns wxPropertyGridPageState in which this property resides.
- wxPropertyGridPageState* GetParentState() const { return m_parentState; }
-#endif
-
- wxPGProperty* GetItemAtY( unsigned int y,
- unsigned int lh,
- unsigned int* nextItemY ) const;
-
- /** Returns (direct) child property with given name (or NULL if not found).
- */
- wxPGProperty* GetPropertyByName( const wxString& name ) const;
-
-#ifdef SWIG
- %extend {
- DocStr(GetClientData,
- "Returns the client data object for a property", "");
- PyObject* GetClientData() {
- wxPyClientData* data = (wxPyClientData*)self->GetClientObject();
- if (data) {
- Py_INCREF(data->m_obj);
- return data->m_obj;
- } else {
- Py_INCREF(Py_None);
- return Py_None;
- }
- }
-
- DocStr(SetClientData,
- "Associate the given client data.", "");
- void SetClientData(PyObject* clientData) {
- wxPyClientData* data = new wxPyClientData(clientData);
- self->SetClientObject(data);
- }
- }
- %pythoncode {
- GetClientObject = GetClientData
- SetClientObject = SetClientData
- }
-#endif
-
-#ifndef SWIG
-
- static wxString* sm_wxPG_LABEL;
-
- /** This member is public so scripting language bindings
- wrapper code can access it freely.
- */
- void* m_clientData;
-
-protected:
- /** Returns text for given column.
- */
- wxString GetColumnText( unsigned int col ) const;
-
- /** Returns (direct) child property with given name (or NULL if not found),
- with hint index.
-
- @param hintIndex
- Start looking for the child at this index.
-
- @remarks
- Does not support scope (ie. Parent.Child notation).
+ @see ChangeFlag()
*/
- wxPGProperty* GetPropertyByNameWH( const wxString& name,
- unsigned int hintIndex ) const;
-
- /** This is used by Insert etc. */
- void AddChild2( wxPGProperty* prop,
- int index = -1,
- bool correct_mode = true );
-
- void DoSetName(const wxString& str) { m_name = str; }
-
- // Call for after sub-properties added with AddChild
- void PrepareSubProperties();
+ void SetFlagRecursively( wxPGPropertyFlags flag, bool set );
- void SetParentalType( int flag )
+ void SetHelpString( const wxString& helpString )
{
- m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
- m_flags |= flag;
+ m_helpString = helpString;
}
- void SetParentState( wxPropertyGridPageState* pstate )
- { m_parentState = pstate; }
-
- // Call after fixed sub-properties added/removed after creation.
- // if oldSelInd >= 0 and < new max items, then selection is
- // moved to it.
- void SubPropsChanged( int oldSelInd = -1 );
-
- int GetY2( int lh ) const;
-
- wxString m_label;
- wxString m_name;
- wxPGProperty* m_parent;
- wxPropertyGridPageState* m_parentState;
-
- wxClientData* m_clientObject;
-
- // Overrides editor returned by property class
- const wxPGEditor* m_customEditor;
-#if wxUSE_VALIDATORS
- // Editor is going to get this validator
- wxValidator* m_validator;
-#endif
- // Show this in front of the value
- //
- // TODO: Can bitmap be implemented with wxPGCell?
- wxBitmap* m_valueBitmap;
-
- wxVariant m_value;
- wxPGAttributeStorage m_attributes;
- wxArrayPtrVoid m_children;
-
- // Extended cell information
- wxArrayPtrVoid m_cells;
-
- // Help shown in statusbar or help box.
- wxString m_helpString;
-
- // Index in parent's property array.
- unsigned int m_arrIndex;
-
- // If not -1, then overrides m_value
- int m_commonValue;
-
- FlagType m_flags;
-
- // Maximum length (mainly for string properties). Could be in some sort of
- // wxBaseStringProperty, but currently, for maximum flexibility and
- // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
- // so short int will fit in just fine.
- short m_maxLen;
-
- // Root has 0, categories etc. at that level 1, etc.
- unsigned char m_depth;
-
- // m_depthBgCol indicates width of background colour between margin and item
- // (essentially this is category's depth, if none then equals m_depth).
- unsigned char m_depthBgCol;
-
- unsigned char m_bgColIndex; // Background brush index.
- unsigned char m_fgColIndex; // Foreground colour index.
-
-private:
- // Called in constructors.
- void Init();
- void Init( const wxString& label, const wxString& name );
-#endif // #ifndef SWIG
-};
-
-// -----------------------------------------------------------------------
+ void SetLabel( const wxString& label ) { m_label = label; }
-//
-// Property class declaration helper macros
-// (wxPGRootPropertyClass and wxPropertyCategory require this).
-//
+ void SetName( const wxString& newName );
-#define WX_PG_DECLARE_DOGETEDITORCLASS \
- virtual const wxPGEditor* DoGetEditorClass() const;
+ /**
+ Changes what sort of parent this property is for its children.
-#ifndef SWIG
- #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
- public: \
- DECLARE_DYNAMIC_CLASS(CLASSNAME) \
- WX_PG_DECLARE_DOGETEDITORCLASS \
- private:
-#else
- #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME)
-#endif
+ @param flag
+ Use one of the following values: wxPG_PROP_MISC_PARENT (for
+ generic parents), wxPG_PROP_CATEGORY (for categories), or
+ wxPG_PROP_AGGREGATE (for derived property classes with private
+ children).
-// Implements sans constructor function. Also, first arg is class name, not
-// property name.
-#define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
-const wxPGEditor* PROPNAME::DoGetEditorClass() const \
-{ \
- return wxPGEditor_##EDITOR; \
-}
+ @remarks You generally do not need to call this function.
+ */
+ void SetParentalType( int flag )
+ {
+ m_flags &= ~(wxPG_PROP_PROPERTY|wxPG_PROP_PARENTAL_FLAGS);
+ m_flags |= flag;
+ }
-// -----------------------------------------------------------------------
+ void SetValueToUnspecified()
+ {
+ wxVariant val; // Create NULL variant
+ SetValue(val, NULL, wxPG_SETVAL_REFRESH_EDITOR);
+ }
-#ifndef SWIG
+ // Helper function (for wxPython bindings and such) for settings protected
+ // m_value.
+ void SetValuePlain( wxVariant value )
+ {
+ m_value = value;
+ }
-/** @class wxPGRootProperty
- @ingroup classes
- Root parent property.
-*/
-class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
-{
-public:
- WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
-public:
+#if wxUSE_VALIDATORS
+ /** Sets wxValidator for a property*/
+ void SetValidator( const wxValidator& validator )
+ {
+ m_validator = wxDynamicCast(validator.Clone(),wxValidator);
+ }
- /** Constructor. */
- wxPGRootProperty();
- virtual ~wxPGRootProperty();
+ /** Gets assignable version of property's validator. */
+ wxValidator* GetValidator() const
+ {
+ if ( m_validator )
+ return m_validator;
+ return DoGetValidator();
+ }
+#endif // wxUSE_VALIDATORS
- virtual bool StringToValue( wxVariant&, const wxString&, int ) const
+ /** Returns client data (void*) of a property.
+ */
+ void* GetClientData() const
{
- return false;
+ return m_clientData;
}
-protected:
-};
+ /** Sets client data (void*) of a property.
+ @remarks
+ This untyped client data has to be deleted manually.
+ */
+ void SetClientData( void* clientData )
+ {
+ m_clientData = clientData;
+ }
-// -----------------------------------------------------------------------
+ /** Returns client object of a property.
+ */
+ void SetClientObject(wxClientData* clientObject)
+ {
+ delete m_clientObject;
+ m_clientObject = clientObject;
+ }
-/** @class wxPropertyCategory
- @ingroup classes
- Category (caption) property.
-*/
-class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
-{
- friend class wxPropertyGrid;
- friend class wxPropertyGridPageState;
- WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
-public:
+ /** Sets managed client object of a property.
+ */
+ wxClientData *GetClientObject() const { return m_clientObject; }
- /** Default constructor is only used in special cases. */
- wxPropertyCategory();
+ /**
+ Sets new set of choices for the property.
- wxPropertyCategory( const wxString& label,
- const wxString& name = wxPG_LABEL );
- ~wxPropertyCategory();
+ @remarks This operation deselects the property and clears its
+ value.
+ */
+ bool SetChoices( const wxPGChoices& choices );
- int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
+ /** Set max length of text in text editor.
+ */
+ inline bool SetMaxLength( int maxLen );
-protected:
- virtual wxString GetValueAsString( int argFlags ) const;
+ /** Call with 'false' in OnSetValue to cancel value changes after all
+ (ie. cancel 'true' returned by StringToValue() or IntToValue()).
+ */
+ void SetWasModified( bool set = true )
+ {
+ if ( set ) m_flags |= wxPG_PROP_WAS_MODIFIED;
+ else m_flags &= ~wxPG_PROP_WAS_MODIFIED;
+ }
- void SetTextColIndex( unsigned int colInd )
- { m_capFgColIndex = (wxByte) colInd; }
- unsigned int GetTextColIndex() const
- { return (unsigned int) m_capFgColIndex; }
+ const wxString& GetHelpString() const
+ {
+ return m_helpString;
+ }
- void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
+ // Use, for example, to detect if item is inside collapsed section.
+ bool IsSomeParent( wxPGProperty* candidate_parent ) const;
- int m_textExtent; // pre-calculated length of text
- wxByte m_capFgColIndex; // caption text colour index
+ /**
+ Adapts list variant into proper value using consecutive
+ ChildChanged-calls.
+ */
+ void AdaptListToValue( wxVariant& list, wxVariant* value ) const;
-private:
- void Init();
-};
+#if wxPG_COMPATIBILITY_1_4
+ /**
+ Adds a private child property.
-#endif // !SWIG
+ @deprecated Use AddPrivateChild() instead.
-// -----------------------------------------------------------------------
+ @see AddPrivateChild()
+ */
+ wxDEPRECATED( void AddChild( wxPGProperty* prop ) );
+#endif
-#ifndef SWIG
+ /**
+ Adds a private child property. If you use this instead of
+ wxPropertyGridInterface::Insert() or
+ wxPropertyGridInterface::AppendIn(), then property's parental
+ type will automatically be set up to wxPG_PROP_AGGREGATE. In other
+ words, all properties of this property will become private.
+ */
+ void AddPrivateChild( wxPGProperty* prop );
-/** @class wxPGChoiceEntry
- Data of a single wxPGChoices choice.
-*/
-class WXDLLIMPEXP_PROPGRID wxPGChoiceEntry : public wxPGCell
-{
-public:
- wxPGChoiceEntry();
- wxPGChoiceEntry( const wxPGChoiceEntry& entry );
- wxPGChoiceEntry( const wxString& label,
- int value = wxPG_INVALID_VALUE )
- : wxPGCell(), m_value(value)
+ /**
+ Appends a new child property.
+ */
+ wxPGProperty* AppendChild( wxPGProperty* prop )
{
- m_text = label;
+ return InsertChild(-1, prop);
}
- wxPGChoiceEntry( const wxString& label,
- int value,
- const wxBitmap& bitmap,
- const wxColour& fgCol = wxNullColour,
- const wxColour& bgCol = wxNullColour )
- : wxPGCell(label, bitmap, fgCol, bgCol), m_value(value)
- {
- }
+ /** Returns height of children, recursively, and
+ by taking expanded/collapsed status into account.
- virtual ~wxPGChoiceEntry()
+ iMax is used when finding property y-positions.
+ */
+ int GetChildrenHeight( int lh, int iMax = -1 ) const;
+
+ /** Returns number of child properties */
+ unsigned int GetChildCount() const
{
+ return (unsigned int) m_children.size();
}
- void SetValue( int value ) { m_value = value; }
+ /** Returns sub-property at index i. */
+ wxPGProperty* Item( unsigned int i ) const
+ { return m_children[i]; }
- int GetValue() const { return m_value; }
+ /** Returns last sub-property.
+ */
+ wxPGProperty* Last() const { return m_children.back(); }
- bool HasValue() const { return (m_value != wxPG_INVALID_VALUE); }
+ /** Returns index of given child property. */
+ int Index( const wxPGProperty* p ) const;
-protected:
- int m_value;
-};
+ // Puts correct indexes to children
+ void FixIndicesOfChildren( unsigned int starthere = 0 );
+ /**
+ Converts image width into full image offset, with margins.
+ */
+ int GetImageOffset( int imageWidth ) const;
-typedef void* wxPGChoicesId;
+ // Returns wxPropertyGridPageState in which this property resides.
+ wxPropertyGridPageState* GetParentState() const { return m_parentState; }
-class WXDLLIMPEXP_PROPGRID wxPGChoicesData
-{
- friend class wxPGChoices;
-public:
- // Constructor sets m_refCount to 1.
- wxPGChoicesData();
+ wxPGProperty* GetItemAtY( unsigned int y,
+ unsigned int lh,
+ unsigned int* nextItemY ) const;
- void CopyDataFrom( wxPGChoicesData* data );
+ /** Returns property at given virtual y coordinate.
+ */
+ wxPGProperty* GetItemAtY( unsigned int y ) const;
- // Takes ownership of 'item'
- void Insert( int index, wxPGChoiceEntry* item )
- {
- wxArrayPtrVoid::iterator it;
- if ( index == -1 )
- {
- it = m_items.end();
- index = m_items.size();
- }
- else
- {
- it = m_items.begin() + index;
- }
+ /** Returns (direct) child property with given name (or NULL if not found).
+ */
+ wxPGProperty* GetPropertyByName( const wxString& name ) const;
- // Need to fix value?
- if ( item->GetValue() == wxPG_INVALID_VALUE )
- item->SetValue(index);
+ // Returns various display-related information for given column
+ void GetDisplayInfo( unsigned int column,
+ int choiceIndex,
+ int flags,
+ wxString* pString,
+ const wxPGCell** pCell );
- m_items.insert(it, item);
- }
+ static wxString* sm_wxPG_LABEL;
- // Delete all entries
- void Clear();
+ /** This member is public so scripting language bindings
+ wrapper code can access it freely.
+ */
+ void* m_clientData;
- size_t GetCount() const { return m_items.size(); }
+protected:
- wxPGChoiceEntry* Item( unsigned int i ) const
- {
- wxCHECK_MSG( i < GetCount(), NULL, "invalid index" );
+ /**
+ Sets property cell in fashion that reduces number of exclusive
+ copies of cell data. Used when setting, for instance, same
+ background colour for a number of properties.
- return (wxPGChoiceEntry*) m_items[i];
- }
+ @param firstCol
+ First column to affect.
- void DecRef()
- {
- m_refCount--;
- wxASSERT( m_refCount >= 0 );
- if ( m_refCount == 0 )
- delete this;
- }
+ @param lastCol
+ Last column to affect.
-private:
- wxArrayPtrVoid m_items;
+ @param preparedCell
+ Pre-prepared cell that is used for those which cell data
+ before this matched unmodCellData.
- // So that multiple properties can use the same set
- int m_refCount;
+ @param srcData
+ If unmodCellData did not match, valid cell data from this
+ is merged into cell (usually generating new exclusive copy
+ of cell's data).
- virtual ~wxPGChoicesData();
-};
+ @param unmodCellData
+ If cell's cell data matches this, its cell is now set to
+ preparedCell.
-#define wxPGChoicesEmptyData ((wxPGChoicesData*)NULL)
+ @param ignoreWithFlags
+ Properties with any one of these flags are skipped.
-#endif // SWIG
+ @param recursively
+ If @true, apply this operation recursively in child properties.
+ */
+ void AdaptiveSetCell( unsigned int firstCol,
+ unsigned int lastCol,
+ const wxPGCell& preparedCell,
+ const wxPGCell& srcData,
+ wxPGCellData* unmodCellData,
+ FlagType ignoreWithFlags,
+ bool recursively );
+ /**
+ Makes sure m_cells has size of column+1 (or more).
+ */
+ void EnsureCells( unsigned int column );
-/** @class wxPGChoices
+ /** Returns (direct) child property with given name (or NULL if not found),
+ with hint index.
- Helper class for managing choices of wxPropertyGrid properties.
- Each entry can have label, value, bitmap, text colour, and background
- colour.
+ @param hintIndex
+ Start looking for the child at this index.
- @library{wxpropgrid}
- @category{propgrid}
-*/
-class WXDLLIMPEXP_PROPGRID wxPGChoices
-{
-public:
- typedef long ValArrItem;
+ @remarks
+ Does not support scope (ie. Parent.Child notation).
+ */
+ wxPGProperty* GetPropertyByNameWH( const wxString& name,
+ unsigned int hintIndex ) const;
- /** Default constructor. */
- wxPGChoices()
- {
- Init();
- }
+ /** This is used by Insert etc. */
+ void DoAddChild( wxPGProperty* prop,
+ int index = -1,
+ bool correct_mode = true );
- /** Copy constructor. */
- wxPGChoices( const wxPGChoices& a )
- {
- if ( a.m_data != wxPGChoicesEmptyData )
- {
- m_data = a.m_data;
- m_data->m_refCount++;
- }
- }
+ void DoGenerateComposedValue( wxString& text,
+ int argFlags = wxPG_VALUE_IS_CURRENT,
+ const wxVariantList* valueOverrides = NULL,
+ wxPGHashMapS2S* childResults = NULL ) const;
- /** Constructor. */
- wxPGChoices( const wxChar** labels, const long* values = NULL )
- {
- Init();
- Set(labels,values);
- }
+ bool DoHide( bool hide, int flags );
- /** Constructor. */
- wxPGChoices( const wxArrayString& labels,
- const wxArrayInt& values = wxArrayInt() )
- {
- Init();
- Set(labels,values);
- }
+ void DoSetName(const wxString& str) { m_name = str; }
- /** Simple interface constructor. */
- wxPGChoices( wxPGChoicesData* data )
- {
- wxASSERT(data);
- m_data = data;
- data->m_refCount++;
- }
+ /** Deletes all sub-properties. */
+ void Empty();
- /** Destructor. */
- ~wxPGChoices()
+ bool HasCell( unsigned int column ) const
{
- Free();
+ if ( m_cells.size() > column )
+ return true;
+ return false;
}
- /**
- Adds to current.
+ void InitAfterAdded( wxPropertyGridPageState* pageState,
+ wxPropertyGrid* propgrid );
- If did not have own copies, creates them now. If was empty, identical
- to set except that creates copies.
+ /**
+ Returns true if child property is selected.
*/
- void Add( const wxChar** labels, const ValArrItem* values = NULL );
+ bool IsChildSelected( bool recursive = false ) const;
- /** Version that works with wxArrayString. */
- void Add( const wxArrayString& arr, const ValArrItem* values = NULL );
+ // Removes child property with given pointer. Does not delete it.
+ void RemoveChild( wxPGProperty* p );
- /** Version that works with wxArrayString and wxArrayInt. */
- void Add( const wxArrayString& arr, const wxArrayInt& arrint );
+ void DoEnable( bool enable );
- /** Adds single item. */
- wxPGChoiceEntry& Add( const wxString& label,
- int value = wxPG_INVALID_VALUE );
+ void DoPreAddChild( int index, wxPGProperty* prop );
- /** Adds a single item, with bitmap. */
- wxPGChoiceEntry& Add( const wxString& label,
- const wxBitmap& bitmap,
- int value = wxPG_INVALID_VALUE );
+ void SetParentState( wxPropertyGridPageState* pstate )
+ { m_parentState = pstate; }
- /** Adds a single item with full entry information. */
- wxPGChoiceEntry& Add( const wxPGChoiceEntry& entry )
+ void SetFlag( wxPGPropertyFlags flag )
{
- return Insert(entry, -1);
+ //
+ // NB: While using wxPGPropertyFlags here makes it difficult to
+ // combine different flags, it usefully prevents user from
+ // using incorrect flags (say, wxWindow styles).
+ m_flags |= flag;
}
- /** Adds single item. */
- wxPGChoiceEntry& AddAsSorted( const wxString& label,
- int value = wxPG_INVALID_VALUE );
+ void ClearFlag( FlagType flag ) { m_flags &= ~(flag); }
- void Assign( const wxPGChoices& a )
- {
- AssignData(a.m_data);
- }
+ // Called when the property is being removed from the grid and/or
+ // page state (but *not* when it is also deleted).
+ void OnDetached(wxPropertyGridPageState* state,
+ wxPropertyGrid* propgrid);
- void AssignData( wxPGChoicesData* data );
+ // Call after fixed sub-properties added/removed after creation.
+ // if oldSelInd >= 0 and < new max items, then selection is
+ // moved to it.
+ void SubPropsChanged( int oldSelInd = -1 );
- /** Delete all choices. */
- void Clear()
- {
- if ( m_data != wxPGChoicesEmptyData )
- m_data->Clear();
- }
+ int GetY2( int lh ) const;
- void EnsureData()
- {
- if ( m_data == wxPGChoicesEmptyData )
- m_data = new wxPGChoicesData();
- }
+ wxString m_label;
+ wxString m_name;
+ wxPGProperty* m_parent;
+ wxPropertyGridPageState* m_parentState;
- /** Gets a unsigned number identifying this list. */
- wxPGChoicesId GetId() const { return (wxPGChoicesId) m_data; };
+ wxClientData* m_clientObject;
- const wxString& GetLabel( size_t ind ) const
- {
- return Item(ind).GetText();
- }
+ // Overrides editor returned by property class
+ const wxPGEditor* m_customEditor;
+#if wxUSE_VALIDATORS
+ // Editor is going to get this validator
+ wxValidator* m_validator;
+#endif
+ // Show this in front of the value
+ //
+ // TODO: Can bitmap be implemented with wxPGCell?
+ wxBitmap* m_valueBitmap;
- size_t GetCount () const
- {
- wxASSERT_MSG( m_data, "When checking if wxPGChoices is valid, "
- "use IsOk() instead of GetCount()" );
- return m_data->GetCount();
- }
+ wxVariant m_value;
+ wxPGAttributeStorage m_attributes;
+ wxArrayPGProperty m_children;
- int GetValue( size_t ind ) const { return Item(ind).GetValue(); }
+ // Extended cell information
+ wxVector<wxPGCell> m_cells;
- /** Returns array of values matching the given strings. Unmatching strings
- result in wxPG_INVALID_VALUE entry in array.
- */
- wxArrayInt GetValuesForStrings( const wxArrayString& strings ) const;
+ // Choices shown in drop-down list of editor control.
+ wxPGChoices m_choices;
- /** 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;
+ // Help shown in statusbar or help box.
+ wxString m_helpString;
- /** Returns true if choices in general are likely to have values
- (depens on that all entries have values or none has)
- */
- bool HasValues() const;
+ // Index in parent's property array.
+ unsigned int m_arrIndex;
- bool HasValue( unsigned int i ) const
- { return (i < m_data->GetCount()) && m_data->Item(i)->HasValue(); }
+ // If not -1, then overrides m_value
+ int m_commonValue;
- int Index( const wxString& str ) const;
- int Index( int val ) const;
+ FlagType m_flags;
- /** Inserts single item. */
- wxPGChoiceEntry& Insert( const wxString& label,
- int index,
- int value = wxPG_INVALID_VALUE );
+ // Maximum length (mainly for string properties). Could be in some sort of
+ // wxBaseStringProperty, but currently, for maximum flexibility and
+ // compatibility, we'll stick it here. Anyway, we had 3 excess bytes to use
+ // so short int will fit in just fine.
+ short m_maxLen;
- /** Inserts a single item with full entry information. */
- wxPGChoiceEntry& Insert( const wxPGChoiceEntry& entry, int index );
+ // Root has 0, categories etc. at that level 1, etc.
+ unsigned char m_depth;
- /** Returns false if this is a constant empty set of choices,
- which should not be modified.
- */
- bool IsOk() const
- {
- return ( m_data != wxPGChoicesEmptyData );
- }
+ // m_depthBgCol indicates width of background colour between margin and item
+ // (essentially this is category's depth, if none then equals m_depth).
+ unsigned char m_depthBgCol;
- const wxPGChoiceEntry& Item( unsigned int i ) const
- {
- wxASSERT( IsOk() );
- return *m_data->Item(i);
- }
+private:
+ // Called in constructors.
+ void Init();
+ void Init( const wxString& label, const wxString& name );
+};
- 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);
+//
+// Property class declaration helper macros
+// (wxPGRootPropertyClass and wxPropertyCategory require this).
+//
-#ifndef SWIG
- /** Does not create copies for itself. */
- void Set( const wxChar** labels, const long* values = NULL )
- {
- Free();
- Add(labels,values);
- }
+#define WX_PG_DECLARE_DOGETEDITORCLASS \
+ virtual const wxPGEditor* DoGetEditorClass() const;
- /** Version that works with wxArrayString.
- TODO: Deprecate this.
- */
- void Set( wxArrayString& arr, const long* values = (const long*) NULL )
- {
- Free();
- Add(arr,values);
- }
-#endif // SWIG
+#ifndef WX_PG_DECLARE_PROPERTY_CLASS
+ #define WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
+ public: \
+ DECLARE_DYNAMIC_CLASS(CLASSNAME) \
+ WX_PG_DECLARE_DOGETEDITORCLASS \
+ private:
+#endif
- /** 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);
- }
+// Implements sans constructor function. Also, first arg is class name, not
+// property name.
+#define WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(PROPNAME,T,EDITOR) \
+const wxPGEditor* PROPNAME::DoGetEditorClass() const \
+{ \
+ return wxPGEditor_##EDITOR; \
+}
- // 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;
- }
- }
+// -----------------------------------------------------------------------
- // Returns data, increases refcount.
- wxPGChoicesData* GetData()
- {
- wxASSERT( m_data->m_refCount != 0xFFFFFFF );
- m_data->m_refCount++;
- return m_data;
- }
+/** @class wxPGRootProperty
+ @ingroup classes
+ Root parent property.
+*/
+class WXDLLIMPEXP_PROPGRID wxPGRootProperty : public wxPGProperty
+{
+public:
+ WX_PG_DECLARE_PROPERTY_CLASS(wxPGRootProperty)
+public:
- // Returns plain data ptr - no refcounting stuff is done.
- wxPGChoicesData* GetDataPtr() const { return m_data; }
+ /** Constructor. */
+ wxPGRootProperty( const wxString& name = wxS("<Root>") );
+ virtual ~wxPGRootProperty();
- // Changes ownership of data to you.
- wxPGChoicesData* ExtractData()
+ virtual bool StringToValue( wxVariant&, const wxString&, int ) const
{
- wxPGChoicesData* data = m_data;
- m_data = wxPGChoicesEmptyData;
- return data;
+ return false;
}
- wxArrayString GetLabels() const;
+protected:
+};
-#ifndef SWIG
- void operator= (const wxPGChoices& a)
- {
- AssignData(a.m_data);
- }
+// -----------------------------------------------------------------------
- wxPGChoiceEntry& operator[](unsigned int i)
- {
- return Item(i);
- }
+/** @class wxPropertyCategory
+ @ingroup classes
+ Category (caption) property.
+*/
+class WXDLLIMPEXP_PROPGRID wxPropertyCategory : public wxPGProperty
+{
+ friend class wxPropertyGrid;
+ friend class wxPropertyGridPageState;
+ WX_PG_DECLARE_PROPERTY_CLASS(wxPropertyCategory)
+public:
- const wxPGChoiceEntry& operator[](unsigned int i) const
- {
- return Item(i);
- }
+ /** Default constructor is only used in special cases. */
+ wxPropertyCategory();
+
+ wxPropertyCategory( const wxString& label,
+ const wxString& name = wxPG_LABEL );
+ ~wxPropertyCategory();
+
+ int GetTextExtent( const wxWindow* wnd, const wxFont& font ) const;
+
+ virtual wxString ValueToString( wxVariant& value, int argFlags ) const;
+ virtual wxString GetValueAsString( int argFlags = 0 ) const;
protected:
- wxPGChoicesData* m_data;
+ void SetTextColIndex( unsigned int colInd )
+ { m_capFgColIndex = (wxByte) colInd; }
+ unsigned int GetTextColIndex() const
+ { return (unsigned int) m_capFgColIndex; }
+
+ void CalculateTextExtent( wxWindow* wnd, const wxFont& font );
+ int m_textExtent; // pre-calculated length of text
+ wxByte m_capFgColIndex; // caption text colour index
+
+private:
void Init();
- void Free();
-#endif // !SWIG
};
-inline bool wxPGProperty::SetChoices( const wxArrayString& labels,
- const wxArrayInt& values )
-{
- wxPGChoices chs(labels, values);
- return SetChoices(chs);
-}
-
// -----------------------------------------------------------------------
#endif // wxUSE_PROPGRID