| Version: 3.2.8

Public Types | Public Member Functions | Protected Member Functions | List of all members
wxGridCellAttr Class Reference
Class List by Category » Grid Related Classes

`#include <wx/grid.h>`

Inheritance diagram for wxGridCellAttr:
[legend]

## Detailed Description

This class can be used to alter the cells' appearance in the grid by 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 Related Classes

## Public Types
enum | wxAttrKind { Any , Cell , Row , Col , Default , Merged }
| Kind of the attribute to retrieve. More...

## Public Member Functions
| wxGridCellAttr (wxGridCellAttr *attrDefault=NULL)
| Default constructor. More...
| wxGridCellAttr (const wxColour &colText, const wxColour &colBack, const wxFont &font, int hAlign, int vAlign)
| Constructor specifying some of the often used attributes. More...
wxGridCellAttr * | Clone () const
| Creates a new copy of this object. More...
void | DecRef ()
| This class is reference counted: it is created with ref count of 1, so calling DecRef() once will delete it. More...
void | GetAlignment (int *hAlign, int *vAlign) const
| Get the alignment to use for the cell with the given attribute. More...
const wxColour & | GetBackgroundColour () const
| Returns the background colour. More...
wxGridCellEditor * | GetEditor (const wxGrid *grid, int row, int col) const
| Returns the cell editor. More...
wxGridCellEditorPtr | GetEditorPtr (const wxGrid *grid, int row, int col) const
| Returns the cell editor. More...
const wxFont & | GetFont () const
| Returns the font. More...
void | GetNonDefaultAlignment (int *hAlign, int *vAlign) const
| Get the alignment defined by this attribute. More...
wxGridCellRenderer * | GetRenderer (const wxGrid *grid, int row, int col) const
| Returns the cell renderer. More...
wxGridCellRendererPtr | GetRendererPtr (const wxGrid *grid, int row, int col) const
| Returns the cell editor. More...
const wxColour & | GetTextColour () const
| Returns the text colour. More...
bool | HasAlignment () const
| Returns true if this attribute has a valid alignment set. More...
bool | HasBackgroundColour () const
| Returns true if this attribute has a valid background colour set. More...
bool | HasEditor () const
| Returns true if this attribute has a valid cell editor set. More...
bool | HasFont () const
| Returns true if this attribute has a valid font set. More...
bool | HasRenderer () const
| Returns true if this attribute has a valid cell renderer set. More...
bool | HasTextColour () const
| Returns true if this attribute has a valid text colour set. More...
void | IncRef ()
| This class is reference counted: it is created with ref count of 1, so calling DecRef() once will delete it. More...
bool | IsReadOnly () const
| Returns true if this cell is set as read-only. More...
void | SetAlignment (int hAlign, int vAlign)
| Sets the alignment. More...
void | SetBackgroundColour (const wxColour &colBack)
| Sets the background colour. More...
void | SetDefAttr (wxGridCellAttr *defAttr)
void | SetEditor (wxGridCellEditor *editor)
| Sets the editor to be used with the cells with this attribute. More...
void | SetFont (const wxFont &font)
| Sets the font. More...
void | SetReadOnly (bool isReadOnly=true)
| Sets the cell as read-only. More...
void | SetRenderer (wxGridCellRenderer *renderer)
| Sets the renderer to be used for cells with this attribute. More...
void | SetTextColour (const wxColour &colText)
| Sets the text colour. More...
void | MergeWith (wxGridCellAttr *mergefrom)
void | SetSize (int num_rows, int num_cols)
void | SetFitMode (wxGridFitMode fitMode)
| Specifies the behaviour of the cell contents if it doesn't fit into the available space. More...
void | SetOverflow (bool allow=true)
| Specifies if cells using this attribute should overflow or clip their contents. More...
void | SetKind (wxAttrKind kind)
bool | HasReadWriteMode () const
bool | HasOverflowMode () const
bool | HasSize () const
void | GetSize (int *num_rows, int *num_cols) const
wxGridFitMode | GetFitMode () const
| Returns the fitting mode for the cells using this attribute. More...
bool | GetOverflow () const
| Returns true if the cells using this attribute overflow into the neighbouring cells. More...
bool | CanOverflow () const
| Returns true if the cell will draw an overflowed text into the neighbouring cells. More...
wxAttrKind | GetKind ()
Public Member Functions inherited from wxSharedClientDataContainer
void * | GetClientData () const
| Get the untyped client data. More...
wxClientData * | GetClientObject () const
| Get a pointer to the client data object. More...
void | SetClientData (void *data)
| Set the untyped client data. More...
void | SetClientObject (wxClientData *data)
| Set the client data object. More...
Public Member Functions inherited from wxRefCounter
| wxRefCounter ()
| Default constructor. More...
void | DecRef ()
| Decrements the reference count associated with this shared data and, if it reaches zero, destroys this instance of wxRefCounter releasing its memory. More...
int | GetRefCount () const
| Returns the reference count associated with this shared data. More...
void | IncRef ()
| Increments the reference count associated with this shared data. More...

## Protected Member Functions
virtual | ~wxGridCellAttr ()
| The destructor is private because only DecRef() can delete us. More...
Protected Member Functions inherited from wxRefCounter
virtual | ~wxRefCounter ()
| Destructor. More...

## Member Enumeration Documentation

## ◆ wxAttrKind

enum wxGridCellAttr::wxAttrKind

Kind of the attribute to retrieve.

See also
  wxGridCellAttrProvider::GetAttr(), wxGridTableBase::GetAttr()

Enumerator
Any | Return the combined effective attribute for the cell.
Cell | Return the attribute explicitly set for this cell.
Row | Return the attribute set for this cells row.
Col | Return the attribute set for this cells column.
Default |
Merged |

## Constructor & Destructor Documentation

## ◆ wxGridCellAttr() [1/2]

wxGridCellAttr::wxGridCellAttr | ( | wxGridCellAttr * | attrDefault = `NULL` | ) |
| explicit

Default constructor.

## ◆ wxGridCellAttr() [2/2]

wxGridCellAttr::wxGridCellAttr | ( | const wxColour & | colText,
|  | const wxColour & | colBack,
|  | const wxFont & | font,
|  | int | hAlign,
|  | int | vAlign
| ) |  |

Constructor specifying some of the often used attributes.

## ◆ ~wxGridCellAttr()

virtual wxGridCellAttr::~wxGridCellAttr | ( |  | ) |
| protected virtual

The destructor is private because only DecRef() can delete us.

## Member Function Documentation

## ◆ CanOverflow()

bool wxGridCellAttr::CanOverflow | ( |  | ) | const

Returns true if the cell will draw an overflowed text into the neighbouring cells.

Note that only left aligned cells currently can overflow. It means that GetFitMode().IsOverflow() should returns true and GetAlignment should returns wxALIGN_LEFT for hAlign parameter.

Since
  3.1.4

## ◆ Clone()

wxGridCellAttr* wxGridCellAttr::Clone | ( |  | ) | const

Creates a new copy of this object.

## ◆ DecRef()

void wxGridCellAttr::DecRef | ( |  | ) |

This class is reference counted: it is created with ref count of 1, so calling DecRef() once will delete it.

Calling IncRef() allows locking it until the matching DecRef() is called.

## ◆ GetAlignment()

void wxGridCellAttr::GetAlignment | ( | int * | hAlign,
|  | int * | vAlign
| ) |  | const

Get the alignment to use for the cell with the given attribute.

If this attribute doesn't specify any alignment, the default attribute alignment is used (which can be changed using wxGrid::SetDefaultCellAlignment() but is left and top by default).

Notice that hAlign and vAlign values are always overwritten by this function, use GetNonDefaultAlignment() if this is not desirable.

Parameters

  hAlign | Horizontal alignment is returned here if this argument is non-NULL. It is one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
  vAlign | Vertical alignment is returned here if this argument is non-NULL. It is one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.

## ◆ GetBackgroundColour()

const wxColour& wxGridCellAttr::GetBackgroundColour | ( |  | ) | const

Returns the background colour.

## ◆ GetEditor()

wxGridCellEditor* wxGridCellAttr::GetEditor | ( | const wxGrid * | grid,
|  | int | row,
|  | int | col
| ) |  | const

Returns the cell editor.

The caller is responsible for calling DecRef() on the returned pointer, use GetEditorPtr() to do it automatically.

## ◆ GetEditorPtr()

wxGridCellEditorPtr wxGridCellAttr::GetEditorPtr | ( | 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

## ◆ GetFitMode()

wxGridFitMode wxGridCellAttr::GetFitMode | ( |  | ) | const

Returns the fitting mode for the cells using this attribute.

The returned wxGridFitMode is always specified, i.e. wxGridFitMode::IsSpecified() always returns true. The default value, if SetFitMode() hadn't been called before, is "overflow".

Since
  3.1.4

## ◆ GetFont()

const wxFont& wxGridCellAttr::GetFont | ( |  | ) | const

Returns the font.

## ◆ GetKind()

wxAttrKind wxGridCellAttr::GetKind | ( |  | ) |

## ◆ GetNonDefaultAlignment()

void wxGridCellAttr::GetNonDefaultAlignment | ( | int * | hAlign,
|  | int * | vAlign
| ) |  | const

Get the alignment defined by this attribute.

Unlike GetAlignment() this function only modifies hAlign and vAlign if this attribute does define a non-default alignment. This means that they must be initialized before calling this function and that their values will be preserved unchanged if they are different from wxALIGN_INVALID.

For example, the following fragment can be used to use the cell alignment if one is defined but right-align its contents by default (instead of left-aligning it by default) while still using the default vertical alignment:

int hAlign = wxALIGN_RIGHT,
vAlign = wxALIGN_INVALID;
attr.GetNonDefaultAlignment(&hAlign, &vAlign);
wxALIGN_INVALID
@ wxALIGN_INVALID
A value different from any valid alignment value.
Definition: defs.h:76
wxALIGN_RIGHT
@ wxALIGN_RIGHT
Definition: defs.h:83

Since
  2.9.1

## ◆ GetOverflow()

bool wxGridCellAttr::GetOverflow | ( |  | ) | const

Returns true if the cells using this attribute overflow into the neighbouring cells.

Prefer using GetFitMode() in the new code.

## ◆ GetRenderer()

wxGridCellRenderer* wxGridCellAttr::GetRenderer | ( | const wxGrid * | grid,
|  | int | row,
|  | int | col
| ) |  | const

Returns the cell renderer.

The caller is responsible for calling DecRef() on the returned pointer, use GetRendererPtr() to do it automatically.

## ◆ GetRendererPtr()

wxGridCellRendererPtr wxGridCellAttr::GetRendererPtr | ( | 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

## ◆ GetSize()

void wxGridCellAttr::GetSize | ( | int * | num_rows,
|  | int * | num_cols
| ) |  | const

## ◆ GetTextColour()

const wxColour& wxGridCellAttr::GetTextColour | ( |  | ) | const

Returns the text colour.

## ◆ HasAlignment()

bool wxGridCellAttr::HasAlignment | ( |  | ) | const

Returns true if this attribute has a valid alignment set.

## ◆ HasBackgroundColour()

bool wxGridCellAttr::HasBackgroundColour | ( |  | ) | const

Returns true if this attribute has a valid background colour set.

## ◆ HasEditor()

bool wxGridCellAttr::HasEditor | ( |  | ) | const

Returns true if this attribute has a valid cell editor set.

## ◆ HasFont()

bool wxGridCellAttr::HasFont | ( |  | ) | const

Returns true if this attribute has a valid font set.

## ◆ HasOverflowMode()

bool wxGridCellAttr::HasOverflowMode | ( |  | ) | const

## ◆ HasReadWriteMode()

bool wxGridCellAttr::HasReadWriteMode | ( |  | ) | const

## ◆ HasRenderer()

bool wxGridCellAttr::HasRenderer | ( |  | ) | const

Returns true if this attribute has a valid cell renderer set.

## ◆ HasSize()

bool wxGridCellAttr::HasSize | ( |  | ) | const

## ◆ HasTextColour()

bool wxGridCellAttr::HasTextColour | ( |  | ) | const

Returns true if this attribute has a valid text colour set.

## ◆ IncRef()

void wxGridCellAttr::IncRef | ( |  | ) |

This class is reference counted: it is created with ref count of 1, so calling DecRef() once will delete it.

Calling IncRef() allows locking it until the matching DecRef() is called.

## ◆ IsReadOnly()

bool wxGridCellAttr::IsReadOnly | ( |  | ) | const

Returns true if this cell is set as read-only.

## ◆ MergeWith()

void wxGridCellAttr::MergeWith | ( | wxGridCellAttr * | mergefrom | ) |

## ◆ SetAlignment()

void wxGridCellAttr::SetAlignment | ( | int | hAlign,
|  | int | vAlign
| ) |  |

Sets the alignment.

hAlign can be one of `wxALIGN_LEFT`, `wxALIGN_CENTRE` or `wxALIGN_RIGHT` and vAlign can be one of `wxALIGN_TOP`, `wxALIGN_CENTRE` or `wxALIGN_BOTTOM`.

## ◆ SetBackgroundColour()

void wxGridCellAttr::SetBackgroundColour | ( | const wxColour & | colBack | ) |

Sets the background colour.

## ◆ SetDefAttr()

void wxGridCellAttr::SetDefAttr | ( | wxGridCellAttr * | defAttr | ) |

Todo:
  Needs documentation.

## ◆ SetEditor()

void wxGridCellAttr::SetEditor | ( | wxGridCellEditor * | editor | ) |

Sets the editor to be used with the cells with this attribute.

## ◆ SetFitMode()

void wxGridCellAttr::SetFitMode | ( | wxGridFitMode | fitMode | ) |

Specifies the behaviour of the cell contents if it doesn't fit into the available space.

See also
  wxGridFitMode

Since
  3.1.4

## ◆ SetFont()

void wxGridCellAttr::SetFont | ( | const wxFont & | font | ) |

Sets the font.

## ◆ SetKind()

void wxGridCellAttr::SetKind | ( | wxAttrKind | kind | ) |

## ◆ SetOverflow()

void wxGridCellAttr::SetOverflow | ( | bool | allow = `true` | ) |

Specifies if cells using this attribute should overflow or clip their contents.

This is the same as calling SetFitMode() with either wxGridFitMode::Overflow() or wxGridFitMode::Clip() argument depending on whether allow is true or false.

Prefer using SetFitMode() directly instead in the new code.

## ◆ SetReadOnly()

void wxGridCellAttr::SetReadOnly | ( | bool | isReadOnly = `true` | ) |

Sets the cell as read-only.

## ◆ SetRenderer()

void wxGridCellAttr::SetRenderer | ( | wxGridCellRenderer * | renderer | ) |

Sets the renderer to be used for cells with this attribute.

Takes ownership of the pointer.

## ◆ SetSize()

void wxGridCellAttr::SetSize | ( | int | num_rows,
|  | int | num_cols
| ) |  |

## ◆ SetTextColour()

void wxGridCellAttr::SetTextColour | ( | const wxColour & | colText | ) |

Sets the text colour.