X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/14bac4b5b91471eacf496e40c4d15bd48768ed89..b545684e13530b21082bc2fc5c64c1c14b852994:/include/wx/propgrid/property.h diff --git a/include/wx/propgrid/property.h b/include/wx/propgrid/property.h index 8f2da0c730..2d8b69c1d0 100644 --- a/include/wx/propgrid/property.h +++ b/include/wx/propgrid/property.h @@ -64,12 +64,12 @@ struct wxPGPaintData 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 @@ -137,30 +137,53 @@ public: 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++; - } + /** + Utility to be called after drawing is done, to revert whatever + changes PreDrawCell() did. - void DecRef() - { - m_refCount--; - if ( !m_refCount ) - delete this; - } -protected: + @param flags + Same as those passed to PreDrawCell(). + */ + void PostDrawCell( wxDC& dc, + const wxPropertyGrid* propGrid, + const wxPGCell& cell, + int flags ) const; +}; -private: - unsigned int m_refCount; + +/** + @class wxPGDefaultRenderer + + Default cell renderer, that can handles the common + scenarios. +*/ +class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer +{ +public: + virtual void Render( wxDC& dc, + const wxRect& rect, + const wxPropertyGrid* propertyGrid, + wxPGProperty* property, + int column, + int item, + int flags ) const; + + virtual wxSize GetImageSize( const wxPGProperty* property, + int column, + int item ) const; + +protected: }; @@ -178,6 +201,7 @@ public: void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; } void SetFgCol( const wxColour& col ) { m_fgCol = col; } void SetBgCol( const wxColour& col ) { m_bgCol = col; } + void SetFont( const wxFont& font ) { m_font = font; } protected: virtual ~wxPGCellData() { } @@ -186,14 +210,18 @@ protected: wxBitmap m_bitmap; wxColour m_fgCol; wxColour m_bgCol; + wxFont m_font; // True if m_text is valid and specified bool m_hasValidText; }; -/** @class wxPGCell +#endif // !SWIG + +/** + @class wxPGCell - Base class for simple wxPropertyGrid cell information. + Base class for wxPropertyGrid cell information. */ class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject { @@ -234,11 +262,32 @@ public: 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 ) @@ -250,39 +299,17 @@ public: return *this; } -protected: +private: virtual wxObjectRefData *CreateRefData() const { return new wxPGCellData(); } virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; }; - -/** @class wxPGDefaultRenderer - - Default cell renderer, that can handles the common - scenarios. -*/ -class WXDLLIMPEXP_PROPGRID wxPGDefaultRenderer : public wxPGCellRenderer -{ -public: - virtual void Render( wxDC& dc, - const wxRect& rect, - const wxPropertyGrid* propertyGrid, - wxPGProperty* property, - int column, - int item, - int flags ) const; - - virtual wxSize GetImageSize( const wxPGProperty* property, - int column, - int item ) const; - -protected: -}; - // ----------------------------------------------------------------------- +#ifndef SWIG + /** @class wxPGAttributeStorage wxPGAttributeStorage is somewhat optimized storage for @@ -451,7 +478,11 @@ wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000, /** 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 }; @@ -639,6 +670,8 @@ wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000 */ // 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 @@ -695,7 +728,7 @@ protected: typedef void* wxPGChoicesId; -class WXDLLIMPEXP_PROPGRID wxPGChoicesData +class WXDLLIMPEXP_PROPGRID wxPGChoicesData : public wxObjectRefData { friend class wxPGChoices; public: @@ -726,20 +759,9 @@ public: return m_items[i]; } - void DecRef() - { - m_refCount--; - wxASSERT( m_refCount >= 0 ); - if ( m_refCount == 0 ) - delete this; - } - private: wxVector m_items; - // So that multiple properties can use the same set - int m_refCount; - virtual ~wxPGChoicesData(); }; @@ -752,7 +774,7 @@ private: Helper class for managing choices of wxPropertyGrid properties. Each entry can have label, value, bitmap, text colour, and background colour. - + wxPGChoices uses reference counting, similar to other wxWidgets classes. This means that assignment operator and copy constructor only copy the reference and not the actual data. Use Copy() member function to create a @@ -783,7 +805,7 @@ public: if ( a.m_data != wxPGChoicesEmptyData ) { m_data = a.m_data; - m_data->m_refCount++; + m_data->IncRef(); } } @@ -796,7 +818,7 @@ public: @param values Values for choices. If NULL, indexes are used. */ - wxPGChoices( const wxChar** labels, const long* values = NULL ) + wxPGChoices( const wxChar* const* labels, const long* values = NULL ) { Init(); Set(labels,values); @@ -823,7 +845,7 @@ public: { wxASSERT(data); m_data = data; - data->m_refCount++; + data->IncRef(); } /** Destructor. */ @@ -844,7 +866,7 @@ public: @param values Values for added choices. If empty, relevant entry indexes are used. */ - void Add( const wxChar** labels, const ValArrItem* values = NULL ); + 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() ); @@ -972,7 +994,7 @@ public: #ifndef SWIG /** Does not create copies for itself. */ - void Set( const wxChar** labels, const long* values = NULL ) + void Set( const wxChar* const* labels, const long* values = NULL ) { Free(); Add(labels,values); @@ -996,8 +1018,8 @@ public: // Returns data, increases refcount. wxPGChoicesData* GetData() { - wxASSERT( m_data->m_refCount != 0xFFFFFFF ); - m_data->m_refCount++; + wxASSERT( m_data->GetRefCount() != -1 ); + m_data->IncRef(); return m_data; } @@ -1063,35 +1085,16 @@ class WXDLLIMPEXP_PROPGRID wxPGProperty : public wxObject public: typedef wxUint32 FlagType; - /** Basic constructor. + /** + Default 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() ) ); - } + /** + Constructor. - @endcode + 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 ); @@ -1272,17 +1275,21 @@ public: 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 warrented 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 @@ -1300,19 +1307,28 @@ public: 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. */ @@ -1539,7 +1555,6 @@ public: 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. @@ -1553,7 +1568,13 @@ public: { return m_value; } -#endif + + // 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. @@ -1583,10 +1604,25 @@ public: /** Returns wxPGCell of given column. + + @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; - wxPGCell& GetCell( unsigned int column ); + /** + Returns wxPGCell of given column, creating one if necessary. + */ + wxPGCell& GetCell( unsigned int column ) + { + return GetOrCreateCell(column); + } + + /** + Returns wxPGCell of given column, creating one if necessary. + */ + wxPGCell& GetOrCreateCell( unsigned int column ); /** Return number of displayed common values for this property. */ @@ -1834,12 +1870,13 @@ public: @param colour Background colour to use. - @param recursively - If @true, children are affected recursively, and any categories - are not. + @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, - bool recursively = false ); + int flags = wxPG_RECURSE ); /** Sets property's text colour. @@ -1847,12 +1884,21 @@ public: @param colour Text colour to use. - @param recursively - If @true, children are affected recursively, and any categories - are not. + @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 SetTextColour( const wxColour& colour, - bool recursively = false ); + int flags = wxPG_RECURSE ); + + /** Set default value of a property. Synonymous to + + @code + SetAttribute("DefaultValue", value); + @endcode + */ + void SetDefaultValue( wxVariant& value ); #ifndef SWIG /** Sets editor for a property. @@ -1975,7 +2021,7 @@ public: void SetLabel( const wxString& label ) { m_label = label; } - inline void SetName( const wxString& newName ); + void SetName( const wxString& newName ); /** Changes what sort of parent this property is for its children. @@ -2000,6 +2046,13 @@ public: SetValue(val); } + // Helper function (for wxPython bindings and such) for settings protected + // m_value. + void SetValuePlain( wxVariant value ) + { + m_value = value; + } + #if wxUSE_VALIDATORS /** Sets wxValidator for a property*/ void SetValidator( const wxValidator& validator ) @@ -2014,7 +2067,7 @@ public: return m_validator; return DoGetValidator(); } -#endif // #if wxUSE_VALIDATORS +#endif // wxUSE_VALIDATORS #ifndef SWIG /** Returns client data (void*) of a property. @@ -2249,6 +2302,13 @@ protected: /** Deletes all sub-properties. */ void Empty(); + bool HasCell( unsigned int column ) const + { + if ( m_cells.size() > column ) + return true; + return false; + } + void InitAfterAdded( wxPropertyGridPageState* pageState, wxPropertyGrid* propgrid );