Merge branch 'grid-attr-smart-ptr'

Use smart pointers in wxGrid code.

See https://github.com/wxWidgets/wxWidgets/pull/1731
This commit is contained in:
Vadim Zeitlin
2020-02-11 22:35:03 +01:00
3 changed files with 213 additions and 153 deletions

View File

@@ -95,6 +95,20 @@ protected:
virtual ~wxGridCellRenderer();
};
/**
Smart pointer wrapping wxGridCellRenderer.
wxGridCellRendererPtr takes ownership of wxGridCellRenderer passed to it on
construction and calls DecRef() on it automatically when it is destroyed.
It also provides transparent access to wxGridCellRenderer methods by allowing
to use objects of this class as if they were wxGridCellRenderer pointers.
@since 3.1.4
@category{grid}
*/
typedef wxObjectDataPtr<wxGridCellRenderer> wxGridCellRendererPtr;
/**
@class wxGridCellAutoWrapStringRenderer
@@ -591,6 +605,20 @@ protected:
virtual ~wxGridCellEditor();
};
/**
Smart pointer wrapping wxGridCellEditor.
wxGridCellEditorPtr takes ownership of wxGridCellEditor passed to it on
construction and calls DecRef() on it automatically when it is destroyed.
It also provides transparent access to wxGridCellEditor methods by allowing
to use objects of this class as if they were wxGridCellEditor pointers.
@since 3.1.4
@category{grid}
*/
typedef wxObjectDataPtr<wxGridCellEditor> wxGridCellEditorPtr;
/**
@class wxGridCellAutoWrapStringEditor
@@ -976,6 +1004,10 @@ public:
changing their attributes from the defaults. An object of this class may be
returned by wxGridTableBase::GetAttr().
Note that objects of this class are reference-counted and it's recommended
to use wxGridCellAttrPtr smart pointer class when working with them to
avoid memory leaks.
@library{wxcore}
@category{grid}
*/
@@ -1054,9 +1086,22 @@ public:
/**
Returns the cell editor.
The caller is responsible for calling DecRef() on the returned pointer,
use GetEditorPtr() to do it automatically.
*/
wxGridCellEditor* GetEditor(const wxGrid* grid, int row, int col) const;
/**
Returns the cell editor.
This method is identical to GetEditor(), but returns a smart pointer,
which frees the caller from the need to call DecRef() manually.
@since 3.1.4
*/
wxGridCellEditorPtr GetEditorPtr(const wxGrid* grid, int row, int col) const;
/**
Returns the font.
*/
@@ -1087,9 +1132,22 @@ public:
/**
Returns the cell renderer.
The caller is responsible for calling DecRef() on the returned pointer,
use GetRendererPtr() to do it automatically.
*/
wxGridCellRenderer* GetRenderer(const wxGrid* grid, int row, int col) const;
/**
Returns the cell editor.
This method is identical to GetRenderer(), but returns a smart pointer,
which frees the caller from the need to call DecRef() manually.
@since 3.1.4
*/
wxGridCellRendererPtr GetRendererPtr(const wxGrid* grid, int row, int col) const;
/**
Returns the text colour.
*/
@@ -1257,6 +1315,20 @@ protected:
virtual ~wxGridCellAttr();
};
/**
Smart pointer wrapping wxGridCellAttr.
wxGridCellAttrPtr takes ownership of wxGridCellAttr passed to it on
construction and calls DecRef() on it automatically when it is destroyed.
It also provides transparent access to wxGridCellAttr methods by allowing
to use objects of this class as if they were wxGridCellAttr pointers.
@since 3.1.4
@category{grid}
*/
typedef wxObjectDataPtr<wxGridCellAttr> wxGridCellAttrPtr;
/**
Base class for header cells renderers.
@@ -1459,7 +1531,7 @@ public:
the cell attribute having the highest precedence.
Notice that the caller must call DecRef() on the returned pointer if it
is non-@NULL.
is non-@NULL. GetAttrPtr() method can be used to do this automatically.
@param row
The row of the cell.
@@ -1474,6 +1546,17 @@ public:
virtual wxGridCellAttr *GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind) const;
/**
Get the attribute to use for the specified cell.
This method is identical to GetAttr(), but returns a smart pointer,
which frees the caller from the need to call DecRef() manually.
@since 3.1.4
*/
wxGridCellAttrPtr GetAttrPtr(int row, int col,
wxGridCellAttr::wxAttrKind kind) const;
/*!
@name Setting attributes.
@@ -2121,10 +2204,24 @@ public:
By default this function is simply forwarded to
wxGridCellAttrProvider::GetAttr() but it may be overridden to handle
attributes directly in the table.
Prefer to use GetAttrPtr() to avoid the need to call DecRef() on the
returned pointer manually.
*/
virtual wxGridCellAttr *GetAttr(int row, int col,
wxGridCellAttr::wxAttrKind kind);
/**
Return the attribute for the given cell.
This method is identical to GetAttr(), but returns a smart pointer,
which frees the caller from the need to call DecRef() manually.
@since 3.1.4
*/
wxGridCellAttrPtr GetAttrPtr(int row, int col,
wxGridCellAttr::wxAttrKind kind);
/**
Set attribute of the specified cell.
@@ -4939,10 +5036,24 @@ public:
attribute is created, associated with the cell and returned. In any
case the caller must call DecRef() on the returned pointer.
Prefer to use GetOrCreateCellAttrPtr() to avoid the need to call
DecRef() on the returned pointer.
This function may only be called if CanHaveAttributes() returns @true.
*/
wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const;
/**
Returns the attribute for the given cell creating one if necessary.
This method is identical to GetOrCreateCellAttr(), but returns a smart
pointer, which frees the caller from the need to call DecRef()
manually.
@since 3.1.4
*/
wxGridCellAttrPtr GetOrCreateCellAttrPtr(int row, int col) const;
/**
Returns a base pointer to the current table object.