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:
-
Value with the cell’s text.
-
Control Id.
-
Base Style.
-
Text Color.
-
Cell Pattern and color as LOGBRUSH object.
-
Borders with LOGPEN objects.
-
Font as a CGXFont object.
-
Horizontal Alignment.
-
Read Only state.
-
Enabled/disabled state (disabled cells cannot become the current cell).
-
Auto-size feature (this allows a cell to grow automatically when the user enters large text).
-
Maximal Length of the text.
-
3d-effect (raised, inset, normal).
-
Vertical Scrollbar specifies if a multiline edit control should display a vertical scrollbar.
-
Wrap Text (also known as Wordbreak).
-
Allow Enter specifies if the edit control should insert a newline when the user presses ENTER.
-
Choice List specifies the alternatives for a combo box, list box, radio buttons or the pushbutton or check box text.
-
TriState property for check boxes.
- User-defined item data pointer.
Each attribute is associated with four attribute methods. An example is the text color:
-
BOOL GetIncludeTextColor() const returns the include-bit.
-
CGXStyle& SetIncludeTextColor(BOOL bInclude) changes the include-bit.
-
BOOL GetTextColor() const returns the text color.
- CGXStyle& SetTextColor(COLORREF rgbColor) changes the color. This method automatically calls SetIncludeTextColor(TRUE).
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