Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Objective Grid User's Guide
Rogue Wave web site:  Home Page  |  Main Documentation Page

2.2 Styles Architecture

As you probably noticed in the overview of Objective Grid classes, styles are the key to the display of the grid and also define most of its behavior. Let's proceed by taking a look at how the styles architecture is implemented. We can then discuss how it ties in with the drawing of the grid.

2.2.1 Style Implementation

The CGXStyle class contains all the information necessary for formatting a cell. A style consists of several attributes, such as text color, borders, control type, and font. All of these styles can be modified by the end user via the CGXStyleSheet dialog.

A very important feature of CGXStyle is support for combining style objects. For example, you can copy only those attributes from one style to a second style that are not initialized in the second style. Objective Grid uses this feature to enable a kind of inheritance. By specifying a base style, you can tell Objective Grid that it should inherit attributes from a base style at run time.

Attributes in the CGXStyle class are combined with an include bit. This include bit is TRUE when an attribute is initialized. If it is FALSE, the attribute is not initialized. When drawing the grid, Objective Grid fills up all uninitialized attributes of the cell style object with values inherited from the base styles.

CGXStyle also supports user-defined style attributes. You can also extend the CGXStyle class with additional attributes. The end user can change these attributes through the CGXStyleSheet. Each CGXStyle object maintains a map of user attributes and provides a method to change their values.

The following attributes are provided by the CGXStyle class:

Style objects are created for those cells that should be drawn and initialized at run time in the CGXGridCore member function ComposeStyleRowCol(). ComposeStyleRowCol() takes a row, a column, and a pointer to a style object as arguments. ComposeStyleRowCol() first calls the GetStyleRowCol() function to get any cell-specific style attributes. ComposeStyleRowCol() adds to the style object any inherited attributes from the row, the column, and the entire grid. Finally, the styles map is checked for any base styles.

The following simplified version of ComposeStyleRowCol() shows how styles are composed.

You may be wondering why all of the access to styles is controlled by one function. This technique allows the developer to bind or dynamically tie the grid object to data such as a database or a live data feed. All the developer has to do is override the virtual CGXGridCore::GetStyleRowCol() function. By centralizing all style operations in one virtual function, the developer can modify the grid in any way imaginable at run time.

What if the developer wants the user to be able to dynamically modify the data? The grid provides a virtual function CGXGridCore::StoreStyleRowCol() that is called before data is stored. By overriding this function, the developer can intercept the end user's changes.

2.2.2 CGXGridCore - Styles Interface

The following CGXGridCore member functions define the interface for style operations.

ChangeBaseStyle()
ChangeColHeaderStyle() 
ComposeStyleRowCol()
GetColStyle()
GetExpressionRowCol()
GetRowStyle()
GetTableStyle()
GetValueRowCol()
ChangeRowHeaderStyle()
ChangeStandardStyle() 
SetExpressionRowCol()
SetStyleRange() 
SetValueRange()

The following are overridable methods:

GetStyleRowCol()
StoreStyleRowCol()

2.2.3 CGXStyle - Class Interface

The CGXStyle class provides accessor methods for all its attributes. The key point is that attributes can be marked as uninitialized. Attributes that are uninitialized will be filled up using base style attributes at run time when drawing the grid.

Each attribute state can be determined or modified with four methods. An example is the text color.

GetIncludeTextColor()
SetIncludeTextColor()
GetTextColor()
SetTextColor()

The various style member functions can be cascaded together to make a very clear and concise block of code. For example, the following code illustrates the formatting of some Objective Grid columns:

The CGXStyle class allows you to operate and combine style objects. The most important member function is ChangeStyle().

ChangeStyle()

ChangeStyle() can perform the following operations with style objects:

SetStyleRange() takes an argument that lets the developer specify the operation to be performed on the style object. This parameter is internally passed to ChangeStyle(). The default argument is gxOverride.



Previous fileTop of DocumentContentsNo linkNext file

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.