home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // File : ColFont.cpp
- // Project : MsgTrace
- // Component : MsgTracer
- //---------------------------------------------------------------------------
- // Description : a colored-font
- //
- /////////////////////////////////////////////////////////////////////////////
- //
- // SourceSafe Strings. Do not change.
- //---------------------------------------------------------------------------
- // $Author: jeskes $
- // $Date: $
- // $Revision: $
- //
- /////////////////////////////////////////////////////////////////////////////
-
- #include "stdafx.h"
- #include "colfont.h"
- #include "dlgs.h"
- #include "resource.h"
-
- /////////////////////////////////////////////////////////////////////////////
-
- static const LPCSTR sFontSection = "fonts";
-
- static const LPCSTR sHeight = "height";
- static const LPCSTR sWeight = "weight";
- static const LPCSTR sItalic = "italic";
- static const LPCSTR sUnderline = "underline";
- static const LPCSTR sCharset = "charset";
- static const LPCSTR sOutprecision = "outprecision";
- static const LPCSTR sQuality = "quality";
- static const LPCSTR sPitchandfamily = "pitchandfamily";
- static const LPCSTR sFacename = "facename";
-
- static const LPCSTR sRed = "color.red";
- static const LPCSTR sGreen = "color.green";
- static const LPCSTR sBlue = "color.blue";
-
- static const LPCSTR sTabSize = "tabsize";
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyFontDialog
- /////////////////////////////////////////////////////////////////////////////
-
- class CMyFontDialog : public CFontDialog
- {
- public:
- CMyFontDialog( LPLOGFONT lplf ) : CFontDialog( lplf ), m_nTabSize( 0 )
- {
- }
-
- int m_nTabSize;
-
- protected:
- virtual BOOL OnInitDialog();
- virtual void OnOK();
-
- private:
- CStatic m_labelTabs;
- CEdit m_editTabs;
- };
-
- /////////////////////////////////////////////////////////////////////////////
-
- BOOL CMyFontDialog::OnInitDialog()
- {
- SetDlgItemInt( IDC_TABSIZE, m_nTabSize );
- return( CFontDialog::OnInitDialog() );
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- void CMyFontDialog::OnOK()
- {
- m_nTabSize = GetDlgItemInt( IDC_TABSIZE );
- CFontDialog::OnOK();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CColoredFont: construction
- /////////////////////////////////////////////////////////////////////////////
-
- CColoredFont::CColoredFont( const CString& sName ) : m_nTabSize( 0 )
- {
- m_sName = sName;
-
- //-----------------------------------------------------------------------
- // read font specifics from profile and create new font
- //-----------------------------------------------------------------------
-
- LOGFONT lf;
- memset( &lf, 0, sizeof( LOGFONT ) );
-
- lf.lfHeight =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sHeight ), 10 );
-
- lf.lfWeight =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sWeight ), FW_THIN );
-
- lf.lfItalic =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sItalic ), 0 );
-
- lf.lfUnderline =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sUnderline ), 0 );
-
- lf.lfCharSet =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sCharset ), ANSI_CHARSET );
-
- lf.lfOutPrecision =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sOutprecision ), OUT_DEFAULT_PRECIS );
-
- lf.lfQuality =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sQuality ), DEFAULT_QUALITY );
-
- lf.lfPitchAndFamily =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sPitchandfamily ), DEFAULT_PITCH | FF_DONTCARE );
-
- lstrcpy( lf.lfFaceName,
- AfxGetApp()->GetProfileString( sFontSection, GetEntry( sFacename ), "MS Sans Serif" ) );
-
- m_pFont = new CFont;
- m_pFont->CreateFontIndirect( &lf );
-
- //-----------------------------------------------------------------------
- // read color specifics from profile
- //-----------------------------------------------------------------------
-
- BYTE bRed =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sRed ), 0 );
-
- BYTE bGreen =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sGreen ), 0 );
-
- BYTE bBlue =
- AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sBlue ), 0 );
-
- m_rgbColor = RGB( bRed, bGreen, bBlue );
-
- //-----------------------------------------------------------------------
- // read tab size
- //-----------------------------------------------------------------------
-
- m_nTabSize = AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sTabSize ), 8 );
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- CColoredFont::~CColoredFont()
- {
- delete m_pFont;
- m_pFont = NULL;
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- BOOL CColoredFont::ChooseColoredFont()
- {
- //-----------------------------------------------------------------------
- // we try to initialize logfont stucture
- //-----------------------------------------------------------------------
-
- LOGFONT lf;
-
- memset( &lf, 0, sizeof( LOGFONT ) );
- m_pFont->GetObject( sizeof( LOGFONT ), &lf );
-
- //-----------------------------------------------------------------------
- // use common dialog box
- //-----------------------------------------------------------------------
-
- CMyFontDialog dlg( &lf );
-
- dlg.m_cf.hwndOwner = ::GetFocus();
- dlg.m_cf.rgbColors = m_rgbColor;
- dlg.m_cf.nFontType = SCREEN_FONTTYPE;
- dlg.m_nTabSize = m_nTabSize;
- dlg.m_cf.Flags |= CF_ENABLETEMPLATE;
- dlg.m_cf.lpTemplateName = MAKEINTRESOURCE( IDD_CHOOSEFONT );
-
- if( IDOK != dlg.DoModal() )
- {
- return( FALSE );
- }
-
- //-----------------------------------------------------------------------
- // destroy old font and create new font - remember color as well
- //-----------------------------------------------------------------------
-
- m_pFont->DeleteObject();
- m_pFont->CreateFontIndirect( &lf );
-
- m_rgbColor = dlg.GetColor();
- m_nTabSize = dlg.m_nTabSize;
-
- //-----------------------------------------------------------------------
- // write font specifics to profile
- //-----------------------------------------------------------------------
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sHeight ), lf.lfHeight );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sWeight ), lf.lfWeight );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sItalic ), lf.lfItalic );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sUnderline ), lf.lfUnderline );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sCharset ), lf.lfCharSet );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sOutprecision ), lf.lfOutPrecision );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sQuality ), lf.lfQuality );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sPitchandfamily ), lf.lfPitchAndFamily );
-
- AfxGetApp()->WriteProfileString(
- sFontSection, GetEntry( sFacename ), lf.lfFaceName );
-
- //-----------------------------------------------------------------------
- // write color specifics to profile
- //-----------------------------------------------------------------------
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sRed ), GetRValue( m_rgbColor ) );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sGreen ), GetGValue( m_rgbColor ) );
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sBlue ), GetBValue( m_rgbColor ) );
-
- //-----------------------------------------------------------------------
- // write tab size
- //-----------------------------------------------------------------------
-
- AfxGetApp()->WriteProfileInt(
- sFontSection, GetEntry( sTabSize ), m_nTabSize );
-
- return( TRUE );
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- LPCSTR CColoredFont::GetEntry( LPCSTR lpszEntry ) const
- {
- static char szBuffer[ 256 ];
-
- wsprintf( szBuffer, "%s.%s", (const char*) m_sName, lpszEntry );
-
- return( szBuffer );
- }
-