class CGXStylesMap: public CObject
The CGXStylesMap class maintains grid-wide styles which 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 their attributes from column-header-style. Standard-style is the base style for all cells in the grid.
CGXStylesMap also maintains controls and user-attributes to be used in the grid.
CGXStylesMap data can be written to the application profile and loaded from it. Registry and serializing is also supported.
Each base style has a unique id. This name is the key for the style-object and can be used in CGXStyle::SetBaseStyle to specify the base style.
The following attributes specify the ids for the default styles:
- wStyleStandard specifies the Standard-style.
- wStyleRowHeader specifies the Row Header-style.
- wStyleColHeader specifies the Column Header-style.
These styles are so-called system styles. This means that the user cannot delete these styles. The programmer can add more system styles that cannot be deleted by the user. Non-system styles can be added and removed at run time through the styles-dialog (see CGXStylesDialog).
See the example for how to attach a CGXStylesMap object to your grid with some supported user attributes.
CGXStylesMap also supports adding user-defined style attributes. These attributes can be used to extend the CGXStyle class with additional attributes. The end user can change the user-defined attributes’ values through the CGXStyleSheet. Each CGXStyle object maintains a map of user attributes and provides a method to change their values.
Note
To apply base styles to cells you first have to get an id for the base style as for example
m_wStyleCombo = GetParam()->GetStylesMap()->GetBaseStyleId(szComboStyle);
m_wStyleError = GetParam()->GetStylesMap()->GetBaseStyleId(szErrorStyle);
SetStyleRange(
CGXRange(5,2,8,3),
CGXStyle()
.SetBaseStyle(m_wStyleCombo)
.SetValue(_T("one"))
);
SetStyleRange(
CGXRange(5,4,8,5),
CGXStyle()
.SetBaseStyle(m_wStyleError)
.SetValue(_T("ALERT!"))
);
#include <gxall.h>
Example
This code shows you how you can attach a CGXStylesMap object to your grid with some supported user attributes.
First, you have to create the object and call CreateStandardStyles. Next, you should register all your user attributes or new base styles and as a final step call ReadProfile.
CGXStylesMap* stylesmap = new CGXStylesMap;
// standard styles
stylesmap->CreateStandardStyles();
// Additional base styles
stylesmap->RegisterStyle(szErrorStyle,
CGXStyle()
.SetTextColor(RGB(255,255,0)) // yellow
.SetInterior(RGB(255,0,0)) // red
.SetFont(
CGXFont()
.SetBold(TRUE)
),
TRUE // system-style (non removable)
);
// user attributes
// style for the cell in "User"-page (user should be able to
// increase/decrease the value with a spin control).
CGXStyle styleSpin;
styleSpin.SetControl(GX_IDS_CTRL_SPINEDIT).SetWrapText(FALSE);
// Validation: warning message
stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MSG,
CGXStyle().SetWrapText(TRUE).SetAutoSize(TRUE));
// Validation: maximum value
stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MAX,
&styleSpin);
// Validation: Minimum value
stylesmap->AddUserAttribute(GX_IDS_UA_VALID_MIN,
&styleSpin);
// Spinbounds: Minimum value
stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_MIN,
&styleSpin);
// Spinbounds: maximum value
stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_MAX,
&styleSpin);
// Spinbounds: wrap value
stylesmap->AddUserAttribute(GX_IDS_UA_SPINBOUND_WRAP,
CGXStyle().SetControl(GX_IDS_CTRL_CHECKBOX3D)
.SetVerticalAlignment(DT_VCENTER)
.SetHorizontalAlignment(DT_CENTER));
// load profile/registry settings
stylesmap->SetSection("My base styles");
stylesmap->ReadProfile();
// attach object to parameter-object
GetParam()->SetStylesMap(stylesmap);
See Also
CGXStyle CGXStylesDialog CGXStyleSheet