The overridable CGXGridCore::OnGridInitialUpdate() method is the core of the initialization process of a grid view or grid control. You should override this method if you have any one-time initialization such as registering controls, setting the number of rows and columns, or initializing properties or styles.
If you use Objective Grid as a dialog control or an embedded window, you are responsible for calling the CGXGridWnd::Initialize() method yourself. This can be done after creating the window with two-phase construction (like CWnd), or in the OnInitDialog() method of your dialog class. Initialize() will call OnGridInitialUpdate().
If you use the grid as a view, OnInitialUpdate() will be called by the framework after the view is first attached to the document, but before the view is initially displayed. In a workbook, the OnInitialUpdate() method is called for each worksheet, even if it is not visible. The OnInitialUpdate() method will call OnGridInitialUpdate().
The grid component distinguishes between shared and unique attributes. CGXGridCore maintains attributes that are unique to each grid object. Shared attributes such as row heights and cell contents have been moved to an extra class, the CGXGridParam class. Each grid object owns a pointer to a parameter object which is an instance of the CGXGridParam class. The parameter object maintains several other objects that can be shared by associated views of one document. The properties object with profile settings, the data object with the cells map, the print device object with the printer settings, the range lists with selected and covered cells, the Undo/Redo lists, and the column widths and row heights are all maintained by CGXGridParam. The parameter object can be maintained by the document or by the grid object itself.
A main task of OnInitialUpdate() is to attach a parameter object to the grid object. If you do override OnInitialUpdate(), you can create a parameter object of your own and attach it to the grid using CGXGridCore::SetParam(). However, if you do not want to maintain the object yourself, the base class version of OnInitialUpdate() calls OnGridInitialUpdate(), which then creates all necessary objects on the heap. OnGridInitialUpdate() creates only those objects which you did not previously initialize.
Here is an example of allocating the parameter object from the heap when using a stand-alone grid view or grid window.
CGXSampleView::OnInitialUpdate() { // When called no reference to a parameter object // is stored in the grid ASSERT(GetParam() == NULL); // Store a reference to a parameter object SetParam(new CGXGridParam); // Now, you could attach the properties, // the stylesmap and the data object to // the parameter object ... // and call the base class OnInitialUpdate method // (this will call OnGridInitialUpdate) CGXGridView::OnInitialUpdate(); // Now, OnInitialUpdate has stored references // to all other objects ASSERT(GetParam()->GetData()); // Data object ASSERT(GetParam()->GetProperties()); // Properties object ASSERT(GetParam()->GetStylesMap()); // StylesMap object } |
Another common requirement is to use the grid view attached to a document. In this case, all data should be maintained by the document. You can embed the parameter object in the document.
// document class class CMyDocument { ... // Attributes CGXGridParam* m_pParam; // parameter object ... }; CMyDocument:: CMyDocument() { m_pParam = NULL; } void CMyDocument::DeleteContents() { delete m_pParam; m_pParam = NULL; } // view class CGXSampleView::OnInitialUpdate() { BOOL bFirstView = FALSE; if (GetDocument()->m_pParam == NULL) { // bFirstView = TRUE indicates that this // is the first view connected to the // document and therefore the data need // to be intialized. bFirstView = TRUE; // construct parameter object GetDocument()->m_pParam = new CGXGridParam; } // else // bFirstView = FALSE indicates that this is // only another view connected to the document // No data need to be initialized. They are // all available in the document already. // pass the pointer to the grid view SetParam(GetDocument()->m_pParam, FALSE); // ˆ-- indicates that document // is responsible for deleting // the object. // Call base class version of this method // (This will call OnGridInitialUpdate) CGXGridView::OnInitialUpdate(); // check if data need to be initialized if (bFirstView) { // Lock any drawing BOOL bOldLock = LockUpdate(); // turn off creation of Undo-information GetParam()->EnableUndo(FALSE); // initialize the grid SetRowCount(...); ... // reenable Undo mechanism GetParam()->EnableUndo(TRUE); // Unlock drawing LockUpdate(bOldLock); } // Just to be sure that everything is redrawn Invalidate(); // Enable Objective Grid internal update hint mechanism // You should put this line as last command into // OnInitialUpdate, because as long as EnableHints is not // called, the modified flag of the document will not be // changed. EnableHints(); } |
Copyright © Rogue Wave Software, Inc. All Rights Reserved.
The Rogue Wave name and logo, and Stingray, are registered trademarks of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.