Basic implementation of grid control. This class is meant to be used as a base class for more specific grid controls.
You can find more information in comments below. Overrided methods can be found in corresponding base classes and interfaces.
class CCustomGrid :public virtual ICustomGrid, public CControl
{
public:
enum STATE // Control states
{
stNormal, // Normal
stHovered, // Mouse pointer is over the control
stFocused, // Control is focused
stFocusedHovered, // Control is focused and mouse pointer is over the control
stDisabled // Control is disabled
};
protected:
void ForceRepaint(); // Cleanup buffer(canvas) and repaint the control
bool ScrollToCell(const Point &coords); // Scroll to specified cell
bool ScrollToActiveCell(); // Scroll to active cell
virtual void UpdateFromStyle(IStyle *style); // Update stylable properties. If you overwrite this method, call CCustomGrid::UpdateFromStyle(style) in it to apply style to the CCustomGrid properties
virtual void CreateColumn( // Called when new column is being created
float &width, // Column width. By default equal to DefaultColumnWidth property value
bool &resizable, // Whether column should be resizable or not. By default equal to DefaultColumnResizable property value
bool &autosize, // Whether column width should depend on cell content(associated IListItem). By default equal to DefaultColumnAutosize property value
bool &enabled, // Whether column enabled or disabled. By default equal to DefaultColumnEnabled property value
bool &fixed, // Whether column is fixed and could not be scrolled in X direction. By default equal to DefaultColumnFixed property value
bool &overflow_hidden); // Whether new cells in column should be drawn with cutting areas which are out of cell(could be overwritten by cell settings). By default equal to DefaultColumnOverflowHidden property value
virtual void CreateRow( // Called when new row is being created
float &height, // Column height. By default equal to DefaultRowHeight property value
bool &resizable, // Whether row should be resizable or not. By default equal to DefaultRowResizable property value
bool &autosize, // Whether row height should depend on cell content(assocciated IListItem). By default equal to DefaultRowAutosize property value
bool &enabled, // Whether row enabled or disabled. By default equal to DefaultRowEnabled property value
bool &fixed, // Whether row is fixed and could not be scrolled in Y direction. By default equal to DefaultRowFixed property value
bool &overflow_hidden); // Whether new cells in row should be drawn with cutting areas which are out of cell(could be overwritten by cell settings). By default equal to DefaultRowOverflowHidden property value
virtual void RenderCell( // Called when cell content should be drawn. By default calls item render method if item is not empty
const int column, // Cell column index
const int row, // Cell row index
IListItem *item, // Item associated with cell. Can be nullptr
const Matrix &matrix, // Transformation matrix to be applied when drawing
const BLOCK *block); // Block constraints to be applied when rendering
virtual PointF GetItemRequiredSize( // Should return cell required size. By default get it from item if it is not empty
const int column, // Cell column index
const int row, // Cell row index
IListItem *item); // Associated item. Can be nullptr
virtual IListItem * CreateItem(const int column, const int row) = 0; // Called to create item for newly created cell with specified coordinates. Can return nullptr if no item should be assigned to the cell
public:
// IControl getters
RectF getClientRect() override;
RectF getRenderRect() override;
CURSOR_TYPE getCursor() override;
// IControl setters
bool setDPI(const Point &value) override;
// IControl methods
void Refresh(const bool refresh_children) override;
// ICustomGrid getters
bool isMultiselect() override;
int getColumns() override;
int getRows() override;
bool isCellEnabled(const int column, const int row) override;
bool isCellHovered(const int column, const int row) override;
bool isCellActive(const int column, const int row) override;
bool isCellSelected(const int column, const int row) override;
bool isCellOverflowHidden(const int column, const int row) override;
float getColumnWidth(const int index) override;
bool isColumnResizable(const int index) override;
bool isColumnAutosize(const int index) override;
bool isColumnEnabled(const int index) override;
bool isColumnFixed(const int index) override;
bool isColumnOverflowHidden(const int index) override;
float getRowHeight(const int index) override;
bool isRowResizable(const int index) override;
bool isRowAutosize(const int index) override;
bool isRowEnabled(const int index) override;
bool isRowFixed(const int index) override;
bool isRowOverflowHidden(const int index) override;
Point getCellAtPosition(const PointF &position, const bool bound) override;
// ICustomGrid setters
bool setMultiselect(const bool value) override;
bool setColumns(const int value) override;
bool setRows(const int value) override;
bool setCellEnabled(const int column, const int row, const bool value) override;
bool setCellActive(const int column, const int row, const bool value) override;
bool setCellSelected(const int column, const int row, const bool value) override;
bool setCellOverflowHidden(const int column, const int row, const bool value) override;
bool setColumnWidth(const int index, const float value) override;
bool setColumnResizable(const int index, const bool value) override;
bool setColumnAutosize(const int index, const bool value) override;
bool setColumnEnabled(const int index, const bool value) override;
bool setColumnFixed(const int index, const bool value) override;
bool setColumnOverflowHidden(const int index, const bool value) override;
bool setRowHeight(const int index, const float value) override;
bool setRowResizable(const int index, const bool value) override;
bool setRowAutosize(const int index, const bool value) override;
bool setRowEnabled(const int index, const bool value) override;
bool setRowFixed(const int index, const bool value) override;
bool setRowOverflowHidden(const int index, const bool value) override;
// ICustomGrid methods
bool SelectAllCells() override;
bool DeselectAllCells() override;
bool DeleteColumn(const int index) override;
bool DeleteRow(const int index) override;
void LockUpdate() override;
void UnlockUpdate() override;
CCustomGrid(const String &class_name);
~CCustomGrid();
// Getters
STATE getState(); // Return control state
SCROLL_VISIBILITY getVerticalScrollVisibility() const; // Return vertical scroll visibility. Default svAuto
SCROLL_VISIBILITY getHorizontalScrollVisibility() const; // Return horizontal scroll visibility. Default svAuto
RectF getBorderWidth() const; // Return border widths. Default { 1, 1, 1, 1 }
RectF getPadding() const; // Return padding. Default { 0, 0, 0, 0 }
float getGridWidth() const; // Return grid line width. Default 1
Color getGridColor(const STATE state) const; // Return grid line color
RectF getBorderRadius(const STATE state) const; // Return border radius
Color getBackgroundColor(const STATE state) const; // Return background color
Gradient *getBackgroundGradient(const STATE state); // Return background gradient
RectC getBorderColor(const STATE state) const; // Return border colors
int getShadowRadius(const STATE state) const; // Return shadow radius
PointF getShadowShift(const STATE state) const; // Return shadow shift
Color getShadowColor(const STATE state) const; // Return shadow color
Color getCornerColor(const STATE state) const; // Return rectangle color between scrollbars
float getScrollInterval() const; // Return scroll interval(in seconds)
float getDefaultColumnWidth() const; // Return default column width. Default 64
float getDefaultRowHeight() const; // Return default row height. Default 24
bool isDefaultColumnResizable() const; // Return whether a column is resizable by default. Default false
bool isDefaultRowResizable() const; // Return whether a row is resizable by default. Default false
bool isDefaultColumnAutosize() const; // Return whether a column width is calculated automatically by default. Default false
bool isDefaultRowAutosize() const; // Return whether a row height is calculated automatically by default. Default false
bool isDefaultColumnEnabled() const; // Return whether a column is enabled by default. Default true
bool isDefaultRowEnabled() const; // Return whether a row is enabled by default. Default true
bool isDefaultColumnFixed() const; // Return whether a column is fixed by default. Default false
bool isDefaultRowFixed() const; // Return whether a row is fixed by default. Default false
bool isDefaultColumnOverflowHidden() const; // Return whether a column content should be clipped by default. Default true
bool isDefaultRowOverflowHidden() const; // Return whether a row content should be clipped by default. Default true
Point getActiveCell() const; // Return active cell coordinates. Return { -1, -1 } if there is no active cell
PointF getCellPosition(const int column, const int row); // Return cell position in control coordinate space
// Setters
bool setVerticalScroll(IBuiltInScroll *value); // Set new vertical scrollbar
bool setHorizontalScroll(IBuiltInScroll *value); // Set new horizontal scrollbar
bool setVerticalScrollVisibility(const SCROLL_VISIBILITY value); // Set vertical scroll visibility
bool setHorizontalScrollVisibility(const SCROLL_VISIBILITY value); // Set horizontal scroll visibility
bool setBorderWidth(const RectF &value); // Set border widths
bool setPadding(const RectF &value); // Set padding
bool setGridWidth(const float value); // Set grid line width
bool setGridColor(const STATE state, const Color &value); // Set grid line color
bool setBorderRadius(const STATE state, const RectF value); // Set border radius
bool setBackgroundColor(const STATE state, const Color &value); // Set background color
bool setBorderColor(const STATE state, const RectC &value); // Set border colors
bool setShadowRadius(const STATE state, const int value); // Set shadow radius
bool setShadowShift(const STATE state, const PointF &value); // Set shadow shift
bool setShadowColor(const STATE state, const Color &value); // Set shadow color
bool setCornerColor(const STATE state, const Color &value); // Set rectangle color between scrollbars
bool setScrollInterval(const float value); // Set scroll interval(in seconds)
bool setDefaultColumnWidth(const float value); // Set default column width
bool setDefaultRowHeight(const float value); // Set default row height
bool setDefaultColumnResizable(const bool value); // Set whether a column is resizable by default
bool setDefaultRowResizable(const bool value); // Set whether a row is resizable by default
bool setDefaultColumnAutosize(const bool value); // Set whether a column width is calculated automatically by default
bool setDefaultRowAutosize(const bool value); // Set whether a row height is calculated automatically by default
bool setDefaultColumnEnabled(const bool value); // Set whether a column is enabled by default
bool setDefaultRowEnabled(const bool value); // Set whether a row is enabled by default
bool setDefaultColumnFixed(const bool value); // Set whether a column is fixed by default
bool setDefaultRowFixed(const bool value); // Set whether a row is fixed by default
bool setDefaultColumnOverflowHidden(const bool value); // Set whether a column content should be clipped by default
bool setDefaultRowOverflowHidden(const bool value); // Set whether a row content should be clipped by default
};
Namespace: | nitisa::standard |
Include: | Standard/Controls/DrawGrid/CustomGrid.h |