|
// Tools\FormatCondition.cpp: Implementierungsdatei
//
#include "stdafx.h"
#include "FormatCondition.h"
// CFormatCondition
CFormatCondition::CFormatCondition( CString strFormatConditionName, int nColumnIndex,
CFormatCondition::eFormatConditionOperator eFormatConditionOperator,
CMCCell *pValue1, CMCCell *pValue2 /* = NULL */,
CWnd *pWnd /* = NULL */ )
{
if ( pWnd == NULL )
pWnd = CWnd::GetDesktopWindow();
this->m_nColumnIndex = nColumnIndex;
this->m_eFormatConditionOperator = eFormatConditionOperator;
this->m_strFormatConditionName = strFormatConditionName;
this->m_pValue1 = pValue1;
this->m_pValue2 = pValue2;
this->m_nLogPixelSY = 0;
this->m_pFont = NULL;
CDC *pDC = pWnd->GetDC();
CFont *pFont = pWnd->GetFont();
if ( pDC )
{
// pFont = pDC->GetCurrentFont();
this->m_nLogPixelSY = pDC->GetDeviceCaps( LOGPIXELSY );
}
if ( pFont )
{
LOGFONT lf;
if ( pFont->GetLogFont( &lf ) )
{
this->m_strFontName = lf.lfFaceName;
this->m_nFontSize = lf.lfHeight;
this->m_bBold = lf.lfWeight != FW_NORMAL;
this->m_bItalic = ( lf.lfItalic != 0 );
this->m_bUnderline = ( lf.lfUnderline != 0 );
this->m_bStrikeThru = ( lf.lfStrikeOut != 0 );
this->Create_Font();
}
}
if ( !this->m_pFont )
{
this->m_strFontName = "Arial";
this->m_nFontSize = 12;
this->m_bBold = false;
this->m_bItalic = false;
this->m_bUnderline = false;
this->m_bStrikeThru = false;
this->Create_Font();
}
if ( pWnd && pDC )
pWnd->ReleaseDC( pDC );
this->m_clrTextColor = ::GetSysColor( COLOR_WINDOWTEXT ); // RGB( 0, 0, 0 );
this->m_clrBackColor = ::GetSysColor( COLOR_WINDOW ); // RGB( 255, 255, 255 );
this->m_bChanged = false;
}
CFormatCondition::~CFormatCondition()
{
if ( this->m_pFont )
delete this->m_pFont;
if ( this->m_pValue1 != NULL )
delete this->m_pValue1;
if ( this->m_pValue2 != NULL )
delete this->m_pValue2;
}
// CFormatCondition-Memberfunktionen
CString CFormatCondition::Get_FormatConditionName( void )
{
return this->m_strFormatConditionName;
}
int CFormatCondition::Get_ColumnIndex( void )
{
return this->m_nColumnIndex;
}
bool CFormatCondition::IsDefaultFormatCondition( void )
{
return this->m_eFormatConditionOperator == FCO_Default;
}
COLORREF CFormatCondition::Get_BackColor( void )
{
return this->m_clrBackColor;
}
COLORREF CFormatCondition::Get_TextColor( void )
{
return this->m_clrTextColor;
}
void CFormatCondition::Set_BackColor( COLORREF clrBackColor )
{
this->m_clrBackColor = clrBackColor;
}
void CFormatCondition::Set_TextColor( COLORREF clrTextColor )
{
this->m_clrTextColor = clrTextColor;
}
bool CFormatCondition::Check_Value( CMCCell *pValue )
{
bool bValueFits = false;
if ( ( pValue == NULL ) || ( this->m_pValue1 == NULL ) )
return false;
CString strValue = pValue->Get_ComparisonValue( );
CString strValue1 = this->m_pValue1->Get_ComparisonValue( );
CString strValue2;
if ( this->m_pValue2 != NULL )
strValue2 = this->m_pValue2->Get_ComparisonValue( );
switch( this->m_eFormatConditionOperator )
{
case FCO_Equal :
bValueFits = ( strValue.Compare( strValue1 ) == 0 );
break;
case FCO_NotEqual :
bValueFits = ( strValue.Compare( strValue1 ) != 0 );
break;
case FCO_GreaterThan :
bValueFits = ( strValue.Compare( strValue1 ) > 0 );
break;
case FCO_LessThan :
bValueFits = ( strValue.Compare( strValue1 ) < 0 );
break;
case FCO_GreaterThanOrEqual :
bValueFits = ( strValue.Compare( strValue1 ) >= 0 );
break;
case FCO_LessThanOrEqual :
bValueFits = ( strValue.Compare( strValue1 ) <= 0 );
break;
case FCO_Between :
bValueFits = ( ( strValue >= strValue1 ) && ( strValue <= strValue2 ) );
break;
case FCO_NotBetween :
bValueFits = !( ( strValue >= strValue1 ) && ( strValue <= strValue2 ) );
break;
case FCO_Contains :
bValueFits = ( strValue.Find( strValue1 ) != -1 );
break;
case FCO_NotContains :
bValueFits = ( strValue.Find( strValue1 ) == -1 );
break;
}
return bValueFits;
}
CFont *CFormatCondition::Get_Font( void )
{
if ( this->m_bChanged )
this->Create_Font();
return this->m_pFont;
}
void CFormatCondition::Create_Font( void )
{
if ( this->m_pFont )
delete this->m_pFont;
this->m_pFont = new CFont( );
if ( this->m_pFont )
this->m_pFont->CreateFont( this->m_nFontSize,
0, 0, 0,
this->m_bBold ? FW_BOLD : FW_NORMAL,
this->m_bItalic,
this->m_bUnderline,
this->m_bStrikeThru,
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
this->m_strFontName );
this->m_bChanged = false;
}
void CFormatCondition::Set_FontName( CString strFontName )
{
if ( strFontName != this->m_strFontName )
{
this->m_strFontName = strFontName;
this->m_bChanged = true;
}
}
void CFormatCondition::Set_FontSize( int nFontSize )
{
int nNewFontSize = -MulDiv( nFontSize, this->m_nLogPixelSY, 72 );
if ( nNewFontSize != this->m_nFontSize )
{
this->m_nFontSize = nNewFontSize;
this->m_bChanged = true;
}
}
void CFormatCondition::Set_Bold( bool bBold )
{
if ( bBold != this->m_bBold )
{
this->m_bBold = bBold;
this->m_bChanged = true;
}
}
void CFormatCondition::Set_Italic( bool bItalic )
{
if ( bItalic != this->m_bItalic )
{
this->m_bItalic = bItalic;
this->m_bChanged = true;
}
}
void CFormatCondition::Set_Underline( bool bUnderline )
{
if ( bUnderline != this->m_bUnderline )
{
this->m_bUnderline = bUnderline;
this->m_bChanged = true;
}
}
void CFormatCondition::Set_StrikeThru( bool bStrikeThru )
{
if ( bStrikeThru != this->m_bStrikeThru )
{
this->m_bStrikeThru = bStrikeThru;
this->m_bChanged = true;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.