Objective Grid : PART I User’s Guide : Chapter 2 Design Overview : Drawing and Updating
Drawing and Updating
The MFC document/view architecture upon which the grid is built takes care of getting paint messages from Windows to Objective Grid via the CView::OnDraw() routine. When the grid object draws, it first calculates the range of cells that need to be drawn. Then it creates a style object for each cell in that range and initializes the cell styles with ComposeStyleRowCol(). After all the style information has been gathered, the inactive cells are drawn by the grid object and then the active cell control draws itself.
In addition to drawing in response to standard Windows paint messages, the grid object also has to keep the document and views synchronized. The MFC document/view model handles most of the updating work for the grid.
CGXGridView can be used with a document or stand-alone. If the view is associated with a document, it is necessary to update all views in response to a change of the document data.
If the user interacts with the grid by typing text in a cell and moving the current cell, the view will call a command to change the value of the current cell. All associated views have to update this cell.
To provide maximum flexibility, the grid provides three overridable functions for each command in the update path. The overridable functions are marked in Figure 4 with M1, M2, and M3.
Figure 4 – How Objective Grid updates are implemented
The developer can intercept updates at the command stage, the storing stage, and even the update stage. For example, changing the value of a cell is done by calling SetStyleRange(). This method calls StoreStyleRowCol() to store the cell contents and UpdateStyleRange() to redraw the cell. The three member functions are all virtual and the member function that reads the grid’s data is also virtual.
By leveraging the document/view architecture and making sure that the programmer can override the functions involved in updating at every critical stage, the uses of Objective Grid have no limit.
CGXGridCore - Commands Interface
The CGXGridCore class provides the following commands. These commands are all associated with a Store-method and an Update-Method as explained above.
HideCols()
Hide/restore the specified columns. If you hide columns and restore them later, the column widths are restored to their old values.
HideRows()
Hides/restores the specified rows. If you hide rows and restore them later, the row heights are restored to their old values.
InsertCols()
Inserts columns.
InsertRows()
Inserts rows.
MoveCols()
Moves columns.
MoveRows()
Moves rows.
RemoveCols()
Removes columns.
RemoveRows()
Removes rows.
MoveCells()
Moves cells from a given source range to a new destination.
CopyCells()
Duplicates cells from a given source range and inserts them at a given destination.
SelectRange()
Turns the selection on/off for a range of cells.
SetColCount()
Inserts or removes columns by calling either InsertCols() or RemoveCols().
SetColWidth()
Changes the column-widths for specific columns.
SetDefaultColWidth()
Changes the default column-width.
SetDefaultRowHeight()
Changes the default row-height.
SetFrozenCols()
Changes the number of frozen columns and columns to be used for row headers.
SetFrozenRows()
Changes the number of frozen rows and rows to be used for column headers.
SetReadOnly()
Changes the read-only state.
SetRowCount()
Inserts or removes rows by calling either InsertRows() or RemoveRows().
SetRowHeight()
Changes the row-height for a specific row.
SetStyleRange()
Applies a given style to the specified range of cells. See previous section.
SetZoom()
Changes the zoom-factor.
Accessor Methods
The following methods encapsulate the access to data and you can easily override them when needed:
GetColCount()
Returns the number of columns in the grid.
GetColWidth()
Returns the width of the specified column.
GetDefaultColWidth()
Returns the default column-width.
GetDefaultRowHeight()
Returns the default row-height.
GetFrozenCols()
Returns the number of frozen columns.
GetFrozenRows()
Returns the number of frozen rows.
GetHeaderCols()
Returns the number of columns to be used for row headers.
GetHeaderRows()
Returns the number of rows to be used for column headers.
GetRowCount()
Returns the number of rows in the grid.
GetRowHeight()
Returns the height of the specified row.
GetStyleRowCol()
Retrieves the pure style for the specified cell (not inheriting attributes from its base styles).
GetZoom()
Returns the zoom factor of the current view.
IsReadOnly()
Returns the read only state.
StoreColWidth()
Stores the width for a specific column.
StoreDefaultColWidth()
Stores the default column-width.
StoreDefaultRowHeight()
Stores the default row-height.
StoreHideCol()
Stores the hidden state for the specified column.
StoreHideRow()
Stores the hidden state for the specified row.
StoreInsertCols()
Inserts columns into the data structure.
StoreInsertRows()
Inserts rows into the data structures, such as the row-heights-map, the cells-map, and the range lists for selected and covered cells.
StoreMoveCols()
Moves columns in the data structure.
StoreMoveRows()
Moves rows in the data structure.
StoreMoveCells()
Moves cells from a given source range to a new destination.
StoreCopyCells()
Duplicates cells from a given source range and inserts them at a given destination.
StoreReadOnly()
Stores the read-only attribute.
StoreRemoveCols()
Removes columns from the data structure.
StoreRemoveRows()
Removes rows from the data structure.
StoreRowHeight()
Stores the height for a specific row.
StoreStyleRowCol()
Stores the pure style for the specified cell into the associated data object.
StoreZoom()
Stores the zoom factor.
CGXGridCore - Drawing Overridables
OnGridDraw()
Called when the grid needs to be drawn.
OnDrawTopLeftBottomRight()
Called to draw a specified range of cells.
OnDrawItem()
Called to draw an individual cell.