📄 chprfont.cpp
字号:
{
/* This function will return the
color index corresponding to
a given color. If no colors
match, the default color will
be returned */
int iFound = -1;
int iLoop;
const int iCount = sizeof( m_luBackColors ) /
sizeof( m_luBackColors[0] );
for (iLoop = 0; (-1 == iFound) && (iLoop < iCount); iLoop++)
{
if (m_luBackColors[iLoop] == luColor)
{
iFound = iLoop;
if (boolDefaultUsed)
{
iFound++;
}
}
}
if (-1 == iFound && boolDefaultUsed )
{
iFound = 0;
}
return iFound;
}
chuint32 ChPrefsColorPage::GetColorValue( chint16 sIndex,
bool boolDefaultUsed )
{
if (boolDefaultUsed)
{
sIndex--;
}
if (-1 == sIndex)
{
return CH_COLOR_DEFAULT;
}
else
{
ASSERT( sIndex >= 0 );
ASSERT( sIndex < (sizeof( m_luBackColors ) /
sizeof( m_luBackColors[0] )) );
return m_luBackColors[sIndex];
}
}
void ChPrefsColorPage::DrawColorItem( LPDRAWITEMSTRUCT lpDrawItemStruct,
CDC* pDC, const CRect& rtItem )
{
int iIndex = lpDrawItemStruct->itemID - 1;
chuint32 luItemData = lpDrawItemStruct->itemData;
COLORREF itemColor = (COLORREF)luItemData;
DWORD itemState = lpDrawItemStruct->itemState;
// Fill the item rect with the color
if ((-1 == iIndex) || IsDefColor( luItemData ))
{
/* Empty item or default window
color */
COLORREF windowColor = GetSysColor( COLOR_WINDOW );
CBrush fillBrush( windowColor );
COLORREF textColor;
string strText;
CFont textFont;
CFont* pOldFont;
CSize sizeText;
int iLeft;
int iTop;
pDC->FillRect( &rtItem, &fillBrush );
// Default color
if (ChWebTrackerManager::WTrackerLoadString( IDS_TEXT_COLOR, strText ))
{
textColor = GetSysColor( COLOR_BTNTEXT );
pOldFont = pDC->SelectObject( m_comboBackColor.GetFont() );
switch( lpDrawItemStruct->CtlID )
{
case IDC_COMBO_LINK_COLOR:
{
textColor = COLOR_DEF_LINK;
break;
}
case IDC_COMBO_FLINK_COLOR :
{
textColor = COLOR_DEF_VIST_LINK;
break;
}
case IDC_COMBO_PLINK_COLOR :
{
textColor = COLOR_DEF_PREFETCH_LINK;
break;
}
}
pDC->SetTextColor( textColor );
// Center the text if possible
sizeText = pDC->GetTextExtent( strText, strText.GetLength() );
iTop = rtItem.top;
if (rtItem.Height() > sizeText.cy)
{
iTop += (rtItem.Height() - sizeText.cy) / 2;
}
iLeft = rtItem.left;
if (rtItem.Width() > sizeText.cx)
{
iLeft += (rtItem.Width() - sizeText.cx) / 2;
}
pDC->SetBkColor( windowColor );
// Draw the text
pDC->ExtTextOut( iLeft, iTop, ETO_OPAQUE, &rtItem, strText,
strText.GetLength(), 0 );
pDC->SelectObject( pOldFont );
}
}
else
{ // Specific color
CBrush fillBrush( itemColor );
pDC->FillRect( &rtItem, &fillBrush );
}
if (itemState & ODS_FOCUS)
{ /* Set the initial state of the
focus */
CRect rtFocus( rtItem );
rtFocus.InflateRect( -1, -1 );
pDC->DrawFocusRect( &rtFocus );
}
else if (itemState & ODS_SELECTED)
{ /* Set the initial state of the
selection */
DrawColorSelect( lpDrawItemStruct, pDC, rtItem, true );
}
}
void ChPrefsColorPage::DrawColorSelect( LPDRAWITEMSTRUCT lpDrawItemStruct,
CDC* pDC, const CRect& rtItem,
bool boolSelected )
{
if (boolSelected)
{
CPen whitePen( PS_SOLID, 0, RGB( 255, 255, 255 ) );
CPen blackPen( PS_SOLID, 0, RGB( 0, 0, 0 ) );
CBrush* pNullBrush;
CPen* pOldPen;
CBrush* pOldBrush;
CRect rtOutline( rtItem );
pNullBrush = CBrush::FromHandle( (HBRUSH)GetStockObject( NULL_BRUSH ) );
pOldBrush = pDC->SelectObject( pNullBrush );
pOldPen = pDC->SelectObject( &whitePen );
pDC->Rectangle( rtOutline );
rtOutline.InflateRect( -1, -1 );
pOldPen = pDC->SelectObject( &blackPen );
pDC->Rectangle( rtOutline );
rtOutline.InflateRect( -1, -1 );
pOldPen = pDC->SelectObject( &whitePen );
pDC->Rectangle( rtOutline );
pDC->SelectObject( pOldPen );
pDC->SelectObject( pOldBrush );
}
else
{
DrawColorItem( lpDrawItemStruct, pDC, rtItem );
}
}
void ChPrefsColorPage::DrawColorSample( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
CDC* pDC;
CRect rtItem;
COLORREF colorBack;
COLORREF colorFore;
chuint32 luBackColor;
chuint32 luForeColor;
COLORREF defForeColor;
string strWindowText;
CRect rtWindow;
int iTop = 0;
int iLeft = 0;
ASSERT( ODT_BUTTON == lpDrawItemStruct->CtlType );
UpdateData();
// Calculate the background color
luBackColor = GetColorValue( m_iBackColor );
if (IsDefColor( luBackColor ))
{
colorBack = GetSysColor( COLOR_WINDOW );
}
else
{
colorBack = (COLORREF)luBackColor;
}
/* Grab a copy of the things that
are needed over and over
again */
pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
rtItem = lpDrawItemStruct->rcItem;
switch( lpDrawItemStruct->CtlID )
{
case IDC_SAMPLE_BACK:
{
strWindowText = "";
break;
}
case IDC_SAMPLE_TEXT:
{
luForeColor = GetColorValue( m_iTextColor );
defForeColor = GetSysColor( COLOR_BTNTEXT );
m_btnSampleText.GetWindowText( strWindowText );
break;
}
case IDC_SAMPLE_LINK:
{
luForeColor = GetColorValue( m_iLinkColor );
defForeColor = COLOR_DEF_LINK;
m_btnSampleLink.GetWindowText( strWindowText );
break;
}
case IDC_SAMPLE_FLINK:
{
luForeColor = GetColorValue( m_iFLinkColor );
defForeColor = COLOR_DEF_VIST_LINK;
m_btnSampleFLink.GetWindowText( strWindowText );
break;
}
case IDC_SAMPLE_PLINK:
{
luForeColor = GetColorValue( m_iPLinkColor );
defForeColor = COLOR_DEF_PREFETCH_LINK;
m_btnSamplePLink.GetWindowText( strWindowText );
break;
}
}
if (!strWindowText.IsEmpty())
{
CSize extents;
if (IsDefColor( luForeColor ))
{
colorFore = defForeColor;
}
else
{
colorFore = (COLORREF)luForeColor;
}
// Measure the text
extents = pDC->GetTextExtent( strWindowText,
strWindowText.GetLength() );
if (extents.cy < rtItem.Height())
{
iTop = rtItem.top + ((rtItem.Height() - extents.cy) / 2);
}
if (extents.cx < rtItem.Width())
{
iLeft = rtItem.left + ((rtItem.Width() - extents.cx) / 2);
}
}
// Fill the rect with the color
pDC->SetBkColor( colorBack );
pDC->SetTextColor( colorFore );
pDC->ExtTextOut( iLeft, iTop, ETO_OPAQUE, &rtItem, strWindowText,
strWindowText.GetLength(), 0 );
}
/*----------------------------------------------------------------------------
ChPrefsColorPage message handlers
----------------------------------------------------------------------------*/
void ChPrefsColorPage::OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct )
{
CPropertyPage ::OnMeasureItem( nIDCtl, lpMeasureItemStruct );
}
void ChPrefsColorPage::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct )
{
switch( nIDCtl )
{
case IDC_COMBO_BACK_COLOR:
case IDC_COMBO_TEXT_COLOR:
case IDC_COMBO_LINK_COLOR:
case IDC_COMBO_FLINK_COLOR:
case IDC_COMBO_PLINK_COLOR:
{
CDC* pDC;
CRect rtItem;
int iSavedDC;
ASSERT( ODT_COMBOBOX == lpDrawItemStruct->CtlType );
/* Grab a copy of the things that
are needed over and over
again */
pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
rtItem = lpDrawItemStruct->rcItem;
/* Save the state of the passed-in
DC */
iSavedDC = pDC->SaveDC();
// Draw the contents of the item
if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE)
{
DrawColorItem( lpDrawItemStruct, pDC, rtItem );
}
else if (lpDrawItemStruct->itemAction & ODA_FOCUS)
{
// Toggle the focus rect
CRect rtFocus( rtItem );
rtFocus.InflateRect( -1, -1 );
pDC->DrawFocusRect( &rtFocus );
}
else if (lpDrawItemStruct->itemAction & ODA_SELECT)
{
// Toggle the selection rect
bool boolSelected;
boolSelected = !!(lpDrawItemStruct->itemState & ODS_SELECTED);
DrawColorSelect( lpDrawItemStruct, pDC, rtItem, boolSelected );
}
// Restore the original DC state
pDC->RestoreDC( iSavedDC );
break;
}
case IDC_SAMPLE_BACK:
case IDC_SAMPLE_TEXT:
case IDC_SAMPLE_LINK:
case IDC_SAMPLE_FLINK:
case IDC_SAMPLE_PLINK:
{
DrawColorSample( lpDrawItemStruct );
break;
}
default:
{
CPropertyPage::OnDrawItem( nIDCtl, lpDrawItemStruct );
break;
}
}
}
void ChPrefsColorPage::OnSelchangeComboBackColor()
{
m_btnSampleBack.Invalidate( false );
m_btnSampleText.Invalidate( false );
m_btnSampleLink.Invalidate( false );
m_btnSampleFLink.Invalidate( false );
m_btnSamplePLink.Invalidate( false );
// Invalidate the color combo boxes
m_comboBackColor.Invalidate( );
m_comboTextColor.Invalidate( );
m_comboLinkColor.Invalidate( );
m_comboFLinkColor.Invalidate( );
m_comboPLinkColor.Invalidate( );
}
void ChPrefsColorPage::OnSelchangeComboTextColor()
{
m_btnSampleText.Invalidate( false );
}
void ChPrefsColorPage::OnSelchangeComboLinkColor()
{
m_btnSampleLink.Invalidate( false );
}
void ChPrefsColorPage::OnSelchangeComboFlinkColor()
{
m_btnSampleFLink.Invalidate( false );
}
void ChPrefsColorPage::OnSelchangeComboPlinkColor()
{
m_btnSamplePLink.Invalidate( false );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -