home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / MSGTRACE.ZIP / MyProjects / MsgTrace / MsgTracer / ColFont.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-30  |  8.2 KB  |  262 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File        : ColFont.cpp
  4. // Project     : MsgTrace
  5. // Component   : MsgTracer
  6. //---------------------------------------------------------------------------
  7. // Description : a colored-font
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10. //
  11. // SourceSafe Strings. Do not change.
  12. //---------------------------------------------------------------------------
  13. // $Author: jeskes $
  14. // $Date: $
  15. // $Revision: $
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18.  
  19. #include "stdafx.h"
  20. #include "colfont.h"
  21. #include "dlgs.h"
  22. #include "resource.h"
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25.  
  26. static const LPCSTR sFontSection     = "fonts";
  27.  
  28. static const LPCSTR sHeight         = "height";
  29. static const LPCSTR sWeight         = "weight";
  30. static const LPCSTR sItalic         = "italic";
  31. static const LPCSTR sUnderline        = "underline";
  32. static const LPCSTR sCharset        = "charset";
  33. static const LPCSTR sOutprecision    = "outprecision";
  34. static const LPCSTR sQuality        = "quality";
  35. static const LPCSTR sPitchandfamily    = "pitchandfamily";
  36. static const LPCSTR sFacename        = "facename";
  37.  
  38. static const LPCSTR sRed            = "color.red";
  39. static const LPCSTR sGreen            = "color.green";
  40. static const LPCSTR sBlue            = "color.blue";
  41.  
  42. static const LPCSTR sTabSize        = "tabsize";
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CMyFontDialog 
  46. /////////////////////////////////////////////////////////////////////////////
  47.  
  48. class CMyFontDialog : public CFontDialog
  49. {
  50. public:
  51.     CMyFontDialog( LPLOGFONT lplf ) : CFontDialog( lplf ), m_nTabSize( 0 ) 
  52.     {
  53.     }
  54.  
  55.     int m_nTabSize;
  56.  
  57. protected:
  58.     virtual BOOL OnInitDialog();
  59.     virtual void OnOK();
  60.  
  61. private:
  62.     CStatic m_labelTabs;
  63.     CEdit m_editTabs;
  64. };                                
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67.  
  68. BOOL CMyFontDialog::OnInitDialog()
  69. {
  70.      SetDlgItemInt( IDC_TABSIZE, m_nTabSize );
  71.     return( CFontDialog::OnInitDialog() );
  72. }
  73.  
  74. /////////////////////////////////////////////////////////////////////////////
  75.  
  76. void CMyFontDialog::OnOK()
  77. {
  78.     m_nTabSize = GetDlgItemInt( IDC_TABSIZE );
  79.     CFontDialog::OnOK();
  80. }
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CColoredFont: construction
  84. /////////////////////////////////////////////////////////////////////////////
  85.  
  86. CColoredFont::CColoredFont( const CString& sName ) : m_nTabSize( 0 )
  87. {
  88.     m_sName = sName;
  89.     
  90.     //-----------------------------------------------------------------------
  91.     // read font specifics from profile and create new font 
  92.     //-----------------------------------------------------------------------
  93.     
  94.     LOGFONT lf;
  95.     memset( &lf, 0, sizeof( LOGFONT ) );
  96.     
  97.     lf.lfHeight = 
  98.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sHeight ), 10 );
  99.     
  100.     lf.lfWeight = 
  101.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sWeight ), FW_THIN );
  102.     
  103.     lf.lfItalic = 
  104.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sItalic ), 0 );
  105.     
  106.     lf.lfUnderline = 
  107.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sUnderline ), 0 );
  108.     
  109.     lf.lfCharSet =
  110.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sCharset ), ANSI_CHARSET );
  111.     
  112.     lf.lfOutPrecision =
  113.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sOutprecision ), OUT_DEFAULT_PRECIS );
  114.  
  115.     lf.lfQuality =
  116.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sQuality ), DEFAULT_QUALITY );
  117.  
  118.     lf.lfPitchAndFamily =
  119.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sPitchandfamily ), DEFAULT_PITCH | FF_DONTCARE );
  120.  
  121.     lstrcpy( lf.lfFaceName, 
  122.              AfxGetApp()->GetProfileString( sFontSection, GetEntry( sFacename ), "MS Sans Serif" ) );
  123.     
  124.     m_pFont = new CFont;
  125.     m_pFont->CreateFontIndirect( &lf );
  126.     
  127.     //-----------------------------------------------------------------------
  128.     // read color specifics from profile
  129.     //-----------------------------------------------------------------------
  130.     
  131.     BYTE bRed = 
  132.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sRed ), 0 ); 
  133.     
  134.     BYTE bGreen = 
  135.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sGreen ), 0 ); 
  136.     
  137.     BYTE bBlue = 
  138.         AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sBlue ), 0 ); 
  139.     
  140.     m_rgbColor = RGB( bRed, bGreen, bBlue );
  141.  
  142.     //-----------------------------------------------------------------------
  143.     // read tab size
  144.     //-----------------------------------------------------------------------
  145.     
  146.     m_nTabSize = AfxGetApp()->GetProfileInt( sFontSection, GetEntry( sTabSize ), 8 ); 
  147. }
  148.     
  149. /////////////////////////////////////////////////////////////////////////////
  150.  
  151. CColoredFont::~CColoredFont()
  152. {
  153.     delete m_pFont;
  154.     m_pFont = NULL;
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158.  
  159. BOOL CColoredFont::ChooseColoredFont()
  160. {
  161.     //-----------------------------------------------------------------------
  162.     // we try to initialize logfont stucture 
  163.     //-----------------------------------------------------------------------
  164.     
  165.     LOGFONT lf;
  166.  
  167.     memset( &lf, 0, sizeof( LOGFONT ) );
  168.     m_pFont->GetObject( sizeof( LOGFONT ), &lf );
  169.     
  170.     //-----------------------------------------------------------------------
  171.     // use common dialog box
  172.     //-----------------------------------------------------------------------
  173.     
  174.     CMyFontDialog dlg( &lf );
  175.     
  176.     dlg.m_cf.hwndOwner = ::GetFocus();
  177.     dlg.m_cf.rgbColors = m_rgbColor;
  178.     dlg.m_cf.nFontType = SCREEN_FONTTYPE;
  179.     dlg.m_nTabSize = m_nTabSize;
  180.     dlg.m_cf.Flags |= CF_ENABLETEMPLATE;
  181.     dlg.m_cf.lpTemplateName = MAKEINTRESOURCE( IDD_CHOOSEFONT );
  182.  
  183.     if( IDOK != dlg.DoModal() )
  184.     {
  185.         return( FALSE );
  186.     }
  187.  
  188.     //-----------------------------------------------------------------------
  189.     // destroy old font and create new font - remember color as well
  190.     //-----------------------------------------------------------------------
  191.     
  192.     m_pFont->DeleteObject();
  193.     m_pFont->CreateFontIndirect( &lf );
  194.     
  195.     m_rgbColor = dlg.GetColor();
  196.     m_nTabSize = dlg.m_nTabSize;
  197.  
  198.     //-----------------------------------------------------------------------
  199.     // write font specifics to profile
  200.     //-----------------------------------------------------------------------
  201.     
  202.     AfxGetApp()->WriteProfileInt( 
  203.         sFontSection, GetEntry( sHeight ), lf.lfHeight );
  204.     
  205.     AfxGetApp()->WriteProfileInt( 
  206.         sFontSection, GetEntry( sWeight ), lf.lfWeight );
  207.     
  208.     AfxGetApp()->WriteProfileInt( 
  209.         sFontSection, GetEntry( sItalic ), lf.lfItalic );
  210.     
  211.     AfxGetApp()->WriteProfileInt( 
  212.         sFontSection, GetEntry( sUnderline ), lf.lfUnderline );
  213.     
  214.     AfxGetApp()->WriteProfileInt( 
  215.         sFontSection, GetEntry( sCharset ), lf.lfCharSet );
  216.     
  217.     AfxGetApp()->WriteProfileInt( 
  218.         sFontSection, GetEntry( sOutprecision ), lf.lfOutPrecision );
  219.  
  220.     AfxGetApp()->WriteProfileInt( 
  221.         sFontSection, GetEntry( sQuality ), lf.lfQuality );
  222.  
  223.     AfxGetApp()->WriteProfileInt( 
  224.         sFontSection, GetEntry( sPitchandfamily ), lf.lfPitchAndFamily );
  225.  
  226.     AfxGetApp()->WriteProfileString( 
  227.         sFontSection, GetEntry( sFacename ), lf.lfFaceName );
  228.     
  229.     //-----------------------------------------------------------------------
  230.     // write color specifics to profile
  231.     //-----------------------------------------------------------------------
  232.     
  233.     AfxGetApp()->WriteProfileInt( 
  234.         sFontSection, GetEntry( sRed ), GetRValue( m_rgbColor ) ); 
  235.     
  236.     AfxGetApp()->WriteProfileInt( 
  237.         sFontSection, GetEntry( sGreen ), GetGValue( m_rgbColor ) ); 
  238.     
  239.     AfxGetApp()->WriteProfileInt( 
  240.         sFontSection, GetEntry( sBlue ), GetBValue( m_rgbColor ) ); 
  241.  
  242.     //-----------------------------------------------------------------------
  243.     // write tab size
  244.     //-----------------------------------------------------------------------
  245.     
  246.     AfxGetApp()->WriteProfileInt( 
  247.         sFontSection, GetEntry( sTabSize ), m_nTabSize ); 
  248.  
  249.     return( TRUE );
  250. }
  251.  
  252. /////////////////////////////////////////////////////////////////////////////
  253.  
  254. LPCSTR CColoredFont::GetEntry( LPCSTR lpszEntry ) const
  255. {
  256.     static char szBuffer[ 256 ];
  257.     
  258.     wsprintf( szBuffer, "%s.%s", (const char*) m_sName, lpszEntry );
  259.     
  260.     return( szBuffer );
  261. }
  262.