// draw checkboxes with icons instead of text
class SECheckBoxWithIcon : public CXTPControlCheckBox
{
DECLARE_XTP_CONTROL(SECheckBoxWithIcon)
public:
SECheckBoxWithIcon()
{
}
virtual CSize GetSize(CDC* pDC)
{
return(CSize(48,22));
}
virtual void Draw(CDC* pDC)
{
// code lifted from CXTPPaintManager::DrawControlToolBarParent
CXTPRibbonTheme* pTheme = dynamic_cast<CXTPRibbonTheme*>(GetPaintManager());
BOOL bPressed = GetPressed(), bSelected = GetSelected(), bEnabled = GetEnabled(), bChecked = GetChecked(), bPopuped = GetPopuped();
CRect rcButton = GetRect();
CSize szCheckBox = DrawControlCheckBoxMark(pTheme, pDC, rcButton, FALSE, bSelected, bPressed, bChecked, bEnabled);
CRect rcCheck = CRect(CPoint(rcButton.left + 3, (rcButton.bottom + rcButton.top - szCheckBox.cy)/2), szCheckBox);
DrawControlCheckBoxMark(pTheme, pDC, rcCheck, TRUE, bSelected, bPressed, bChecked, bEnabled);
// draw the icon
CPoint pt = CPoint(rcButton.left + szCheckBox.cx + 5, rcButton.top + 2);
if (CXTPImageManagerIcon* pImage = GetImage())
{
pImage->Draw(pDC, pt);
}
}
// protected function lifted from Codejock for access here
CSize /*CXTPRibbonTheme::*/DrawControlCheckBoxMark(CXTPRibbonTheme* pPaintManager, CDC* pDC, CRect rc, BOOL bDraw, BOOL bSelected, BOOL bPressed, BOOL bChecked, BOOL bEnabled)
{
if (!bDraw)
return CSize(13, 13);
CXTPOffice2007Image* pImage = pPaintManager->LoadImage(/*FormatName*/(_T("TOOLBARBUTTONCHECKBOX")));
ASSERT(pImage);
if (!pImage)
return CSize(13, 13);
int nState = 0;
if (!bEnabled)
nState = 3;
else if (bSelected && bPressed)
nState = 2;
else if (bSelected)
nState = 1;
if (bChecked == 1)
nState += 4;
if (bChecked == 2)
nState += 8;
pImage->DrawImage(pDC, rc, pImage->GetSource(nState, 12), CRect(0, 0, 0, 0));
return CSize(13, 13);
}
};
IMPLEMENT_XTP_CONTROL(SECheckBoxWithIcon, CXTPControlCheckBox)