<< Return to Main Index

< Return to Class Index

class CGXStyle: public CObject

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

A very important feature of CGXStyle is its support for combining style objects. For example, you can copy only those attributes from one style to another style which are not initialized in the other 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.

Base styles make it possible to group specific kinds of cells and make them have similar attributes.  The predefined base styles are: row-header-style, column-header-style and standard-style.  Row header cells inherit their attributes from row-header-style.  Column headers inherit from column-header-style.  Standard-style is the base style for all cells in the grid.

Attributes in the CGXStyle class are combined with an include-bit. This include-bit is TRUE when an attribute is initialized and FALSE if the attribute is not initialized. When drawing the grid, Objective Grid fills up all uninitialized attributes of the cell’s style object with the base style’s attributes. If the GetInclude... methods return FALSE, Objective Grid will try to initialize this attribute with the base style’s setting. If GetInclude... methods return TRUE, the specific setting will be used for drawing.

CGXStyle also supports user-defined style attributes. You can 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. See the CGXStylesMap class for registering user-defined attributes.

The following attributes are provided by the CGXStyle class:

Each attribute is associated with four attribute methods. An example is the text color:

SetIncludeTextColor and SetTextColor return the this-pointer, and therefore the programmer can easily initialize several attributes with one statement.

The usage of styles in the source code looks very intelligible. The following example illustrates the formatting of some columns:

   SetStyleRange(
      CGXRange().SetCols(2, 4),
      CGXStyle()
         .SetHorizontalAlignment(DT_LEFT)
         .SetVerticalAlignment(DT_BOTTOM)
         .SetBorder(gxBorderLeft, CGXPen().SetStyle(PS_DOTTED) )
         .SetFont(
            CGXFont()
               .SetSize(10)
               .SetBold(TRUE) )
         .SetControl(GX_IDS_CTRL_COMBO)
         .SetChoiceList("one\ntwo\nthree\nfour\nfive\n"));

#include <gxall.h>

See Also

CGXStyleSheet CGXStylesMap CGXFont CGXBrush CGXPen

CGXStyle

Class Members