class CGXCheckBox: public CGXControl
The CGXCheckBox class implements a checkbox control that can be used in grid cells. When constructing a CGXCheckBox,you can choose between 3d-look and old MS Windows 3.x look.
You might also draw your own bitmaps for selected and unselected state and pass the resource id of a bitmap to the CGXCheckBox constructor. Take a look at the default bitmaps in gxres.rc (e.g., GX_IDB_CHECK_95).
You can specify the checkbox text with CGXStyle::SetChoiceList,and you can specify if you want to have tri-state checkbox with CGXStyle::SetTriState.The user can change these style settings through the CGXStyleSheet dialog (“control”-page).
The state of the checkbox is passed through the style object’s value-attribute (CGXStyle::SetValue). The representation for the checked and unchecked state is set to be "1" and "0" by default (as defined by the user attributes below). In a tri-state checkbox an empty string in the corresponding style's value represents the indeterminate state.
You can specify the checked/unchecked representation in the style object with the user attributes GX_IDS_UA_CHECKBOX_CHECKED and GX_IDS_UA_CHECKBOX_UNCHECKED. The default setting is “1” for checked and “0” for unchecked. Other values are treated as undetermined.
Example:
// Checkbox: "TRUE" is checked, "FALSE" is unchecked
// instead of "1" and "0"
StandardStyle().SetUserAttribute(GX_IDS_UA_CHECKBOX_CHECKED, _T("TRUE"));
StandardStyle().SetUserAttribute(GX_IDS_UA_CHECKBOX_UNCHECKED, _T("FALSE"));
Other style attributes that specify the appearance of the cell are:
·Text color with SetColor.
·Background color with SetInterior.
·Horizontal alignment with SetHorizontalAlignment.
·Vertical alignment with SetVerticalAlignment.
·Cell frame 3d-effect (raised, inset, normal) with SetDraw3dFrame.
·Borders with SetBorder.
·Font with SetFont.
- the user clicks the checkbox, the control’s OnClickedButton method is called. The default behavior of OnClickedButton is to toggle the checkbox state and store the new value in the grid. As a final step it calls CGXGridCore::OnClickedButtonRowCol.
To process this event, you can either subclass CGXCheckBox and override the control’s OnClickedButton method or simply override OnClickedButtonRowCol in your CGXGridCore-derived class.
The default ids for CGXCheckBox controls are:
·GX_IDS_CTRL_CHECKBOX with old Windows 3.x look
·GX_IDS_CTRL_CHECKBOX3D with newer 3d-look.
You can apply checkboxes to cells with
SetStyleRange(range, CGXStyle()
.SetControl(GX_IDS_CTRL_CHECKBOX3D));
See the attached example, which shows how to implement an ownerdrawn checkbox.
#include <gxall.h>
Example
This sample class implements an ownerdrawn checkbox. When the bitmap is loaded from the resource file, all white pixels in the bitmap will be replaced with the default window color as specified in the system settings.
///////////////////////////////////////////////////////////////////
// CGridSample8CheckBox
class CGridSample8CheckBox: public CGXCheckBox
{
public:
CGridSample8CheckBox(CGXGridCore* pGrid);
virtual COLORREF GetColorValue(COLORREF rgb, BOOL bPrint);
};
///////////////////////////////////////////////////////////////////
// CGridSample8CheckBox
// see the bitmap IDS_CHECK_SAMPLE8 for how to draw your own
// checkboxes. You should supply 5 bitmaps. All bitmaps
// should have the same size (e.g. m_nCheckBoxSize = 16)
// the checkboxes are arranged as follows in the bitmap:
// 0) unchecked
// 1) checked
// 2) unchecked with scope (grey background)
// 3) checked with scope (grey background)
// 4) undetermined
CGridSample8CheckBox::CGridSample8CheckBox(CGXGridCore* pGrid)
: CGXCheckBox(pGrid, TRUE, IDB_CHECK_SAMPLE8, IDB_CHECK_SAMPLE8)
{
// size of a checkbox
m_nCheckBoxSize = 16;
}
// override GetColorValue to adjust colors in the bitmap
// with system colors
COLORREF CGridSample8CheckBox::GetColorValue(COLORREF rgb, BOOL bPrint)
{
switch (rgb)
{
// Replace the white color in the bitmap with
// the background color of the window
case RGB(255, 255, 255):
return bPrint ? RGB(255, 255, 255) : GetSysColor(COLOR_WINDOW);
default:
return rgb;
}
}
Here is how to register this checkbox in your OnInitialUpdate routine:
RegisterControl(GX_IDS_CTRL_CHECKBOX,
new CGridSample8CheckBox(this));
See Also
CGXGridCore::RegisterControl CGXStyle::SetControl CGXControl::OnClickedButton CGXGridCore::OnClickedButtonRowCol