Extending Functionality in Objective Grid
The primary tool to change and/or add functionality to one of Objective Grid’s classes is subclassing. In your derived class, you can add new methods to gain functionality, and override existing virtual methods to change existing functionality. One of the hallmarks of Objective Grid is that its classes are rich in virtual functions so you can easily home in on exactly the behavior you want to modify.
Here is an example of how you can change the functionality of an existing class so it can handle things in a different manner. The CGXEditControl class implements a text input control that can be used to display and edit text in cells. Through CGXStyle, you can make this text right-justified, left-justified, or centered within the cell. But suppose you want to make sure there is a 2 pixel margin around the cell so the text will never be displayed within 2 pixels of the border (regardless of the alignment). One way to implement this behavior is to subclass CGXEditControl and override its member method GetCellRect(), which returns the interior rectangle for the cell.
 
CRect CBorderedEditCtrl::GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT rectItem,
const CGXStyle* pStyle)
{
// declarations
class CBorderedEditCtrl: public CGXEditControl
{
GRID_DECLARE_CONTROL(CBorderedEditCtrl)
public:
CBorderedEditCtrl(CGXGridCore* pGrid, UINT nID);
virtual CRect GetCellRect(ROWCOL nRow, ROWCOL nCol, LPRECT
rectItem = NULL, const CGXStyle* pStyle = NULL);
};
 
// implementation
GRID_IMPLEMENT_CONTROL(CBorderedEditCtrl, CGXEditControl)
 
CBorderedEditCtrl::CBorderedEditCtrl(CGXGridCore* pGrid, UINT nID):
CGXEditControl(pGrid, nID) {};
{
CRect r = GetCellRect( nRow, nCol, rectItem, pStyle);
r.InflateRect( -2, -2); //deflate the rectangle
 
return r;
}
Before you jump in and start subclassing one of Objective Grid’s classes, you should always check the class’s description, as there may be a property setting that affects the behavior you want. If so, you can avoid the work of subclassing and simply set the property.