Drawing Classes
Figure 5 – Drawing class hierarchy
This class hierarchy diagram may be a little different from most that you’ve seen. That’s because Objective Grid uses C++ multiple inheritance and MFC does not. Objective Grid uses multiple inheritance in order to support both a CWnd and a CView derivative via the CGXGridCore class. The sections below describe each class in detail and explain why Objective Grid uses this approach.
The CGXGridCore class encapsulates all of the drawing logic for the grid and its components. CGXGridCore responsibilities include:
*Drawing and scrolling the grid.
*Executing commands such as formatting cells, inserting rows and columns, and moving rows and columns.
*Handling Undo and Redo commands.
*Managing the position of the current cell.
*Interpreting user interactions such as mouse clicks and keyboard strokes.
*Freezing rows and columns.
*Inverting selected cells.
The CGXGridView and CGXGridWnd classes inherit from both an MFC class and CGXGridCore. This use of multiple inheritance is necessary to avoid duplication of the drawing logic in both a CWnd and a CView derivative. By placing all of the drawing logic in CGXGridCore, Objective Grid centralizes the drawing logic in one class.
The CGXView class serves as base class for a variety of views. It adds support for storing printer settings in a view or document and provides interfaces that make it easier to place the grid in a tabbed window.
This class presents the grid component as a view. CGXGridView supports CView-like features for the grid including splitter window support, printing, and print-preview. CGXGridView is designed as a base class and is typically not instantiated.
CGXGridWnd gives the grid a CWnd interface so that it can be used like a control. In other words, CGXGridWnd can be placed in a dialog and manipulated with the Visual C++ dialog editor. Like CWnd, CGXGridWnd is rarely instantiated. Instead, the developer derives from CGXGridWnd, overrides the virtual functions to obtain the desired behavior and then instantiates the derivative.
CGXGridHandleView lets you dynamically attach a CGXGridCore-derived class to a CView derivative. The advantage of this technique is that CGXGridHandleView can be bound with any CGXGridCore derivative at run time. It is not statically bound to CGXGridCore as CGXGridView is. CGXGridHandleView delegates all mouse actions and user input to the CGXGridCore object.
CGXGridHandleWnd lets you dynamically attach a CGXGridCore-derived class to a CWnd derivative so that it can be used like a control.
Objective Grid uses CGXGridHint internally to perform optimized updating of all views.