⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chprfont.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------

            .###.  ###     ###       ,#,          .###.    ,#######,
         ,####""   ###    .###     ,##'##,     ,####""   .##'    `##.
        ###        ###########    ,##' `##,   ###       ####      ####
        ###..      ###'    ###  ,###########, ####..    `###,    ,##'
          `######  ###     ###  `##'     `##'   `######   `########'


	Copyright 1995, Chaco Communications, Inc. All rights reserved.
	Unpublished -- Rights reserved under the copyright laws of the United
	States.  Use of a copyright notice is precautionary only and does no
	imply publication or disclosure.

	This software contains confidential information and trade secrets of
	Chaco Communications, Inc.  Use, disclosure, or reproduction is
	prohibited without the prior express written permission of Chaco
	Communications, Inc.

	RESTRICTED RIGHTS LEGEND

	Use, duplication, or disclosure by the Government is subject to
	restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
	Technical Data and Computer Software clause at DFARS 252.227-7013.

	Chaco Communications, Inc.
	10164 Parkwood Drive, Suite 8, Cupertino, CA, 95014-1533

------------------------------------------------------------------------------

	This file contains the implementation of the ChConnPrefsPage class,
	which manages connection preferences.

----------------------------------------------------------------------------*/


#include "stdafx.h"
#include <ChReg.h>
#include "resource.h"
#include "ChMFrame.h"
#include "ChPrFont.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// ChPrFont property page

IMPLEMENT_DYNCREATE(ChPrFont, CPropertyPage)

ChPrFont::ChPrFont() : CPropertyPage(ChPrFont::IDD),
					m_reg( CH_COMPANY_NAME, CH_HTML_PRODUCT_NAME, CH_FONT_GROUP ),
					m_boolInitialized( false )
{
	//{{AFX_DATA_INIT(ChPrFont)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}

ChPrFont::~ChPrFont()
{
}

void ChPrFont::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ChPrFont)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


bool ChPrFont::OnSetActive()
{
	bool	boolResult;

	boolResult = CPropertyPage::OnSetActive();

	if (!m_boolInitialized)
	{
		CStatic		*pName;
		string		strSize;

		m_reg.Read( CH_FONT_PROPORTIONAL, m_strProportionalFont, 
							CH_FONT_PROPORTIONAL_DEF );
 		m_reg.Read( CH_FONT_PROPORTIONAL_SIZE, strSize, 
 						CH_FONT_PROPORTIONAL_SIZE_DEF );

		m_iProportionalPointSize = atoi( strSize );

		m_reg.Read( CH_FONT_FIXED, m_strFixedFont, CH_FONT_FIXED_DEF );
		m_reg.Read( CH_FONT_FIXED_SIZE, strSize, CH_FONT_FIXED_SIZE_DEF );

												// Set the proportional font name
		m_iFixedPointSize = atoi( strSize );
		pName = (CStatic *)GetDlgItem( IDC_STAT_PROPORTIONAL );
		pName->SetWindowText( m_strProportionalFont );
												// Set the fixed font name

		pName = (CStatic *)GetDlgItem( IDC_STAT_FIXED );
		pName->SetWindowText( m_strFixedFont );
											/* Set the initialized flag so
												that we don't do this again */
		m_boolInitialized = true;
	}

	return boolResult;
}


BOOL ChPrFont::OnKillActive()
{
	UpdateData( true );
	
	if (m_boolInitialized)
	{
		char	strNum[30];
		m_reg.Write( CH_FONT_PROPORTIONAL, m_strProportionalFont );

		_itoa( m_iProportionalPointSize, strNum, 10 );
 		m_reg.Write( CH_FONT_PROPORTIONAL_SIZE, strNum );

		m_reg.Write( CH_FONT_FIXED, m_strFixedFont );
		_ltoa( m_iFixedPointSize, strNum, 10 );
		m_reg.Write( CH_FONT_FIXED_SIZE, strNum );

		ChMainFrame* pFrame = (ChMainFrame*)GetParentFrame(); 
		if ( pFrame )
		{
			pFrame->GetHTMLWnd()->SendMessage( WM_HTML_FONT_CHANGE );
		}

	}
	return ( true );
}



BEGIN_MESSAGE_MAP(ChPrFont, CPropertyPage)
	//{{AFX_MSG_MAP(ChPrFont)
	ON_BN_CLICKED(IDC_CHOOSE_FIXED, OnChooseFixedFont)
	ON_BN_CLICKED(IDC_CHOOSE_PROPORTIONAL, OnChooseProportionalFont)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// ChPrFont message handlers

void ChPrFont::OnChooseFixedFont() 
{
	// TODO: Add your control notification handler code here
	LOGFONT	lf;
	ChMemClearStruct( &lf );

#ifdef CH_MSW
	HDC			hDC = ::GetDC( ::GetDesktopWindow() );
	int iPixelY = -1 * ::GetDeviceCaps(hDC, LOGPIXELSY);
	::ReleaseDC(::GetDesktopWindow(), hDC );
	
	lf.lfHeight = ( iPixelY * m_iFixedPointSize / 72);
	lf.lfWeight 		= FW_LIGHT;
	lf.lfCharSet 		= ANSI_CHARSET;
	lf.lfOutPrecision 	= OUT_STROKE_PRECIS;
	lf.lfClipPrecision 	= CLIP_STROKE_PRECIS;
	lf.lfQuality 		= DEFAULT_QUALITY;
	lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
	lstrcpy(lf.lfFaceName, m_strFixedFont );	 // should we get the name from the preference file ???
#else
	cerr << "XXX" << __FILE__ << ":" << __LINE__ << endl;	
#endif
	
	CFontDialog fixedFont( &lf, ( CF_FIXEDPITCHONLY | CF_SCREENFONTS |
							  CF_LIMITSIZE | CF_INITTOLOGFONTSTRUCT), NULL, this );

	fixedFont.m_cf.Flags &= ~CF_SHOWHELP; 
	fixedFont.m_cf.nSizeMin = 6;
	fixedFont.m_cf.nSizeMax = 16;
	fixedFont.m_cf.iPointSize = m_iFixedPointSize;
	if ( fixedFont.DoModal() == IDOK )
	{
		CStatic		*pName;
		m_strFixedFont = lf.lfFaceName;
		m_iFixedPointSize = fixedFont.m_cf.iPointSize/10;		
												// Set the fixed font name

		pName = (CStatic *)GetDlgItem( IDC_STAT_FIXED );
		pName->SetWindowText( m_strFixedFont );
	}
}

void ChPrFont::OnChooseProportionalFont() 
{
	// TODO: Add your control notification handler code here
	LOGFONT	lf;
	ChMemClearStruct( &lf );

#ifdef CH_MSW
	HDC			hDC = ::GetDC( ::GetDesktopWindow() );
	int iPixelY = -1 * ::GetDeviceCaps(hDC, LOGPIXELSY);
	::ReleaseDC(::GetDesktopWindow(), hDC );
	
	lf.lfHeight = ( iPixelY * m_iProportionalPointSize / 72);
	lf.lfWeight 		= FW_LIGHT;
	lf.lfCharSet 		= ANSI_CHARSET;
	lf.lfOutPrecision 	= OUT_STROKE_PRECIS;
	lf.lfClipPrecision 	= CLIP_STROKE_PRECIS;
	lf.lfQuality 		= DEFAULT_QUALITY;
	lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
	lstrcpy(lf.lfFaceName, m_strProportionalFont );	 // should we get the name from the preference file ???
#else
	cerr << "XXX" << __FILE__ << ":" << __LINE__ << endl;	
#endif
	
	CFontDialog propFont( &lf, ( CF_SCALABLEONLY | CF_SCREENFONTS |
							  CF_LIMITSIZE | CF_INITTOLOGFONTSTRUCT), NULL, this );

	propFont.m_cf.Flags &= ~CF_SHOWHELP; 
	propFont.m_cf.nSizeMin = 6;
	propFont.m_cf.nSizeMax = 16;
	propFont.m_cf.iPointSize = m_iProportionalPointSize;

	if ( propFont.DoModal() == IDOK )
	{
		m_strProportionalFont = lf.lfFaceName;
		m_iProportionalPointSize = propFont.m_cf.iPointSize/10;		
												// Set the proportional font name
		CStatic		*pName;
		pName = (CStatic *)GetDlgItem( IDC_STAT_PROPORTIONAL );
		pName->SetWindowText( m_strProportionalFont );
	}
	
}


/*----------------------------------------------------------------------------
	ChPrefsColorPage class
----------------------------------------------------------------------------*/

IMPLEMENT_DYNCREATE( ChPrefsColorPage, CPropertyPage )

ChPrefsColorPage::ChPrefsColorPage() :
					CPropertyPage( ChPrefsColorPage::IDD ),
					m_regColor( CH_COMPANY_NAME, CH_HTML_PRODUCT_NAME, CH_COLOR_GROUP ),
					m_boolInitialized( false )
{												   
	//{{AFX_DATA_INIT(ChPrefsColorPage)
	m_iBackColor = -1;
	m_iTextColor = -1;
	m_iLinkColor = -1;
	m_iFLinkColor = -1;
	m_iPLinkColor = -1;
	//}}AFX_DATA_INIT
}

ChPrefsColorPage::~ChPrefsColorPage()
{
}

void ChPrefsColorPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(ChPrefsColorPage)
	DDX_Control(pDX, IDC_SAMPLE_BACK, m_btnSampleBack);
	DDX_Control(pDX, IDC_SAMPLE_TEXT, m_btnSampleText);
	DDX_Control(pDX, IDC_SAMPLE_LINK, m_btnSampleLink);
	DDX_Control(pDX, IDC_SAMPLE_FLINK, m_btnSampleFLink);
	DDX_Control(pDX, IDC_SAMPLE_PLINK, m_btnSamplePLink);
	DDX_Control(pDX, IDC_COMBO_BACK_COLOR, m_comboBackColor);
	DDX_Control(pDX, IDC_COMBO_TEXT_COLOR, m_comboTextColor);
	DDX_Control(pDX, IDC_COMBO_LINK_COLOR, m_comboLinkColor);
	DDX_Control(pDX, IDC_COMBO_FLINK_COLOR, m_comboFLinkColor);
	DDX_Control(pDX, IDC_COMBO_PLINK_COLOR, m_comboPLinkColor);
	DDX_CBIndex(pDX, IDC_COMBO_BACK_COLOR, m_iBackColor);
	DDX_CBIndex(pDX, IDC_COMBO_TEXT_COLOR, m_iTextColor);
	DDX_CBIndex(pDX, IDC_COMBO_LINK_COLOR, m_iLinkColor);
	DDX_CBIndex(pDX, IDC_COMBO_FLINK_COLOR, m_iFLinkColor);
	DDX_CBIndex(pDX, IDC_COMBO_PLINK_COLOR, m_iPLinkColor);
	//}}AFX_DATA_MAP
}


bool ChPrefsColorPage::OnSetActive()
{
	bool	boolResult;

	boolResult = CPropertyPage::OnSetActive();

	if (!m_boolInitialized)
	{
		chuint32		luColor;
		DWORD			dwStyle;
											// Initialize the color lists

		InitColorList( m_comboBackColor, IDS_TEXT_COLOR );
		InitColorList( m_comboTextColor, IDS_TEXT_COLOR );
		InitColorList( m_comboLinkColor, IDS_TEXT_COLOR );
		InitColorList( m_comboFLinkColor, IDS_TEXT_COLOR );
		InitColorList( m_comboPLinkColor, IDS_TEXT_COLOR );

											// Read the registry colors

		m_regColor.Read( CH_COLOR_BACK, luColor, CH_COLOR_DEFAULT );
		m_iBackColor = GetColorIndex( luColor );
		m_regColor.Read( CH_COLOR_TEXT, luColor, CH_COLOR_DEFAULT );
		m_iTextColor = GetColorIndex( luColor );
		m_regColor.Read( CH_COLOR_LINK, luColor, CH_COLOR_DEFAULT );
		m_iLinkColor = GetColorIndex( luColor );
		m_regColor.Read( CH_COLOR_FLINK, luColor, CH_COLOR_DEFAULT );
		m_iFLinkColor = GetColorIndex( luColor );
		m_regColor.Read( CH_COLOR_PLINK, luColor, CH_COLOR_DEFAULT );
		m_iPLinkColor = GetColorIndex( luColor );

		UpdateData( false );
											/* Set the background button to
												clip siblings */
		dwStyle = m_btnSampleBack.GetStyle();
		dwStyle |= WS_CLIPSIBLINGS;
		SetWindowLong( m_btnSampleBack.m_hWnd, GWL_STYLE, dwStyle );

											/* Set the initialized flag so
												that we don't do this again */
		m_boolInitialized = true;
	}

	return boolResult;
}


BOOL ChPrefsColorPage::OnKillActive()
{
	if (m_boolInitialized)
	{
		chint32		luColor;

		UpdateData();

		luColor = GetColorValue( m_iBackColor );
		m_regColor.Write( CH_COLOR_BACK, luColor );
		luColor = GetColorValue(  m_iTextColor );
		m_regColor.Write( CH_COLOR_TEXT, luColor );
		luColor = GetColorValue( m_iLinkColor );
		m_regColor.Write( CH_COLOR_LINK, luColor );
		luColor = GetColorValue( m_iFLinkColor );
		m_regColor.Write( CH_COLOR_FLINK, luColor );
		luColor = GetColorValue( m_iPLinkColor );
		m_regColor.Write( CH_COLOR_PLINK, luColor );

											/* Send message to all HTML windows
												to update font */
		ChMainFrame* pFrame = (ChMainFrame*)GetParentFrame(); 
		if ( pFrame )
		{
			pFrame->GetHTMLWnd()->SendMessage( WM_HTML_COLOR_CHANGE );
		}
	} 

	return true;
}


BEGIN_MESSAGE_MAP(ChPrefsColorPage, CPropertyPage)
	//{{AFX_MSG_MAP(ChPrefsColorPage)
	ON_WM_MEASUREITEM()
	ON_WM_DRAWITEM()
	ON_CBN_SELCHANGE(IDC_COMBO_BACK_COLOR, OnSelchangeComboBackColor)
	ON_CBN_SELCHANGE(IDC_COMBO_FLINK_COLOR, OnSelchangeComboFlinkColor)
	ON_CBN_SELCHANGE(IDC_COMBO_LINK_COLOR, OnSelchangeComboLinkColor)
	ON_CBN_SELCHANGE(IDC_COMBO_PLINK_COLOR, OnSelchangeComboPlinkColor)
	ON_CBN_SELCHANGE(IDC_COMBO_TEXT_COLOR, OnSelchangeComboTextColor)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/*----------------------------------------------------------------------------
	ChPrefsColorPage protected members
----------------------------------------------------------------------------*/
	
const chuint32	ChPrefsColorPage::m_luBackColors[] = {
									RGB( 255, 255, 255 ),	// white
									RGB( 192, 192, 192 ),	// lt grey
									RGB( 128, 128, 128 ),	// dk grey
									RGB( 0, 0, 0 ),			// black
									RGB( 255, 0, 0 ),		// red
									RGB( 255, 0, 255 ),		// magenta
									RGB( 0, 0, 255 ),		// blue
									RGB( 0, 255, 255 ),		// cyan
									RGB( 0, 255, 0 ),		// green
									RGB( 255, 255, 0 ),		// yellow
									RGB( 128, 0, 0 ),		// dk red
									RGB( 128, 0, 128 ),		// dk magenta
									RGB( 0, 0, 128 ),		// dk blue
									RGB( 0, 128, 128 ),		// dk cyan
									RGB( 0, 128, 0 ),		// dk green
									RGB( 128, 128, 0 ),		// dk yellow
									};


void ChPrefsColorPage::InitColorList( CComboBox& comboColor,
										chuint16 suExtraColorText )
{
	int					iLoop;
	const int			iCount = sizeof( m_luBackColors ) /
									sizeof( m_luBackColors[0] );

	if (suExtraColorText)
	{										// Add the extra color
		chuint32		luData;

		luData = CH_COLOR_DEFAULT | suExtraColorText;
		comboColor.AddString( (LPCSTR)luData );
	}

	for (iLoop = 0; iLoop < iCount; iLoop++)
	{
		comboColor.AddString( (LPCSTR)m_luBackColors[iLoop] );
	}
}


chint16 ChPrefsColorPage::GetColorIndex( chuint32 luColor,
											bool boolDefaultUsed )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -