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

📄 chprefsworld.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

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

	Implementation of the ChWorldPrefsPage class.

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

// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/ChPrefsWorld.cpp,v 2.3 1996/09/12 19:09:59 pritham Exp $

#include "headers.h"

#include <cderr.h>

#include "ChWorld.h"
#include "ChPrefsWorld.h"

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


/*----------------------------------------------------------------------------
	Constants
----------------------------------------------------------------------------*/

#define TINTIN_OPEN_DLG_FLAGS	(OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |\
									OFN_HIDEREADONLY | OFN_ENABLETEMPLATE)


/*----------------------------------------------------------------------------
	ChWorldPrefsPage class
----------------------------------------------------------------------------*/

IMPLEMENT_DYNCREATE( ChWorldPrefsPage, ChPropertyBaseClass )

ChWorldPrefsPage::ChWorldPrefsPage() :
		ChPropertyBaseClass( ChWorldPrefsPage::IDD, 0 
			#if !defined( CH_PUEBLO_PLUGIN )
				,ChWorldDLL.hModule 
			#endif
		),
		m_reg( WORLD_PREFS_GROUP )
{
	m_reg.ReadBool( WORLD_PREFS_ECHO, m_boolEcho, true );
	m_reg.ReadBool( WORLD_PREFS_ECHO_BOLD, m_boolBold, true );
	m_reg.ReadBool( WORLD_PREFS_ECHO_ITALIC, m_boolItalic, false );
	m_reg.ReadBool( WORLD_PREFS_PAUSE_DISCONNECT, m_boolPauseOnDisconnect,
					true );

	//{{AFX_DATA_INIT(ChWorldPrefsPage)
	//}}AFX_DATA_INIT
}

ChWorldPrefsPage::~ChWorldPrefsPage()
{
}

void ChWorldPrefsPage::DoDataExchange( CDataExchange* pDX )
{
	ChPropertyBaseClass::DoDataExchange( pDX );

	//{{AFX_DATA_MAP(ChWorldPrefsPage)
	DDX_Check(pDX, IDC_ECHO_BOLD, m_boolBold);
	DDX_Check(pDX, IDC_ECHO_INPUT, m_boolEcho);
	DDX_Check(pDX, IDC_ECHO_ITALIC, m_boolItalic);
	DDX_Check(pDX, IDC_PAUSE_DISCONNECT, m_boolPauseOnDisconnect);
	//}}AFX_DATA_MAP
}


void ChWorldPrefsPage::UpdateButtons()
{
	CButton*	pEchoInput = (CButton*)GetDlgItem( IDC_ECHO_INPUT );

	if (0 == pEchoInput->GetCheck())
	{
		GetDlgItem( IDC_ECHO_BOLD )->EnableWindow( false );
		GetDlgItem( IDC_ECHO_ITALIC )->EnableWindow( false );
		GetDlgItem( IDC_ECHO_STYLE_BOX )->EnableWindow( false );
	}
	else
	{
		GetDlgItem( IDC_ECHO_BOLD )->EnableWindow();
		GetDlgItem( IDC_ECHO_ITALIC )->EnableWindow();
		GetDlgItem( IDC_ECHO_STYLE_BOX )->EnableWindow();
	}
}


#if defined( CH_PUEBLO_PLUGIN )
BOOL ChWorldPrefsPage::OnKillActive( )
{
	UpdateData();

	m_reg.WriteBool( WORLD_PREFS_ECHO, m_boolEcho );
	m_reg.WriteBool( WORLD_PREFS_ECHO_BOLD, m_boolBold );
	m_reg.WriteBool( WORLD_PREFS_ECHO_ITALIC, m_boolItalic );
	m_reg.WriteBool( WORLD_PREFS_PAUSE_DISCONNECT, m_boolPauseOnDisconnect );

	return true;
}
#else
void ChWorldPrefsPage::OnCommit()
{
	if (0 != m_hWnd)
	{
		UpdateData();

		m_reg.WriteBool( WORLD_PREFS_ECHO, m_boolEcho );
		m_reg.WriteBool( WORLD_PREFS_ECHO_BOLD, m_boolBold );
		m_reg.WriteBool( WORLD_PREFS_ECHO_ITALIC, m_boolItalic );
		m_reg.WriteBool( WORLD_PREFS_PAUSE_DISCONNECT, m_boolPauseOnDisconnect );
	}

	ChPropertyBaseClass::OnCommit();
}
#endif


BEGIN_MESSAGE_MAP( ChWorldPrefsPage, ChPropertyBaseClass )
	//{{AFX_MSG_MAP(ChWorldPrefsPage)
	ON_BN_CLICKED(IDC_ECHO_INPUT, OnEchoInput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/*----------------------------------------------------------------------------
	ChWorldPrefsPage message handlers
----------------------------------------------------------------------------*/

bool ChWorldPrefsPage::OnInitDialog() 
{
	ChPropertyBaseClass ::OnInitDialog();

	CenterWindow();
	UpdateButtons();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void ChWorldPrefsPage::OnEchoInput() 
{
	UpdateButtons();
}


/*----------------------------------------------------------------------------
	ChTextInputPrefsPage class
----------------------------------------------------------------------------*/
	
IMPLEMENT_DYNCREATE( ChTextInputPrefsPage, ChPropertyBaseClass )

ChTextInputPrefsPage::ChTextInputPrefsPage() :
			ChPropertyBaseClass( ChTextInputPrefsPage::IDD, 0
			#if !defined( CH_PUEBLO_PLUGIN )
				, ChWorldDLL.hModule 
			#endif
			 ),
			m_reg( WORLD_PREFS_GROUP ),
			m_boolDirty( false ),
			m_boolInitialized( false ),
			m_sEditLines( 0 )
{
	//{{AFX_DATA_INIT(ChTextInputPrefsPage)
	m_iKeyMap = -1;
	m_boolClear = FALSE;
	m_strLineCount = _T("");
	//}}AFX_DATA_INIT
}

ChTextInputPrefsPage::~ChTextInputPrefsPage()
{
}


bool ChTextInputPrefsPage::OnSetActive()
{
	bool	boolResult;

	boolResult = ChPropertyBaseClass::OnSetActive();

	if (!m_boolInitialized)
	{
		string		strKeyMap;

		m_reg.Read( WORLD_PREFS_KEYMAP, strKeyMap,
					WORLD_PREFS_KEYMAP_DEF );
		m_keyMap.Set( strKeyMap );

		m_reg.Read( WORLD_EDIT_LINES, m_sEditLines,
					WORLD_EDIT_LINES_DEF );
		m_reg.ReadBool( WORLD_PREFS_CLEAR, m_boolClear,
						WORLD_PREFS_CLEAR_DEF );

		m_reg.Read( WORLD_TINTIN_FILE, m_strTinTinFile,
					WORLD_TINTIN_FILE_DEF );
		DisplayTinTinName( m_strTinTinFile );
											// Initialize the dialog data
		UpdateData( false );
											// Limit the edit field to 2 digits
		m_editLineCount.LimitText( 2 );
											/* Set the initialized flag so
												that we don't do this again */
		m_boolInitialized = true;
	}

	return boolResult;
}


bool ChTextInputPrefsPage::OnKillActive()
{
	bool	boolSuccess;

	if (boolSuccess = ChPropertyBaseClass::OnKillActive())
	{
		if ((GetEditLines() <= 0) || (GetEditLines() > WORLD_EDIT_LINES_MAX))
		{
			string		strFormat;
			string		strOut;

			LOADSTRING( IDS_LINES_OUT_OF_RANGE, strFormat );
			strOut.Format( strFormat, (int)WORLD_EDIT_LINES_MAX );
			MessageBox( strOut );
			m_editLineCount.SetFocus();

			boolSuccess = false;
		}
	}

	if ( boolSuccess )
	{
		UpdateData();

		m_reg.Write( WORLD_PREFS_KEYMAP, m_keyMap.GetName() );
		m_reg.Write( WORLD_EDIT_LINES, m_sEditLines );
		m_reg.WriteBool( WORLD_PREFS_CLEAR, m_boolClear );
		m_reg.Write( WORLD_TINTIN_FILE, m_strTinTinFile );
	}

	return boolSuccess;
}


#if !defined( CH_PUEBLO_PLUGIN )

void ChTextInputPrefsPage::OnCommit()
{
	if (m_boolInitialized)
	{										// Write data to registry

		m_reg.Write( WORLD_PREFS_KEYMAP, m_keyMap.GetName() );
		m_reg.Write( WORLD_EDIT_LINES, m_sEditLines );
		m_reg.WriteBool( WORLD_PREFS_CLEAR, m_boolClear );
		m_reg.Write( WORLD_TINTIN_FILE, m_strTinTinFile );
	}     
}
#endif


void ChTextInputPrefsPage::SetEditLines( chint16 sLines )
{
	m_sEditLines = sLines;

	if (GetEditLines() <= 0)
	{
		m_sEditLines = 1;
	}
	else if (GetEditLines() > WORLD_EDIT_LINES_MAX)
	{
		m_sEditLines = WORLD_EDIT_LINES_MAX;
	}
}


void ChTextInputPrefsPage::DoDataExchange( CDataExchange* pDX )
{
	ChPropertyBaseClass::DoDataExchange( pDX );

	if (!pDX->m_bSaveAndValidate)
	{
		m_strLineCount.Format( "%hd", m_sEditLines );

		switch( m_keyMap )
		{
			case keymapEmacs:
			{
				m_iKeyMap = 1;
				break;
			}

			default:
			{
				m_iKeyMap = 0;
				break;
			}
		}
	}

	//{{AFX_DATA_MAP(ChTextInputPrefsPage)
	DDX_Control(pDX, IDC_EDIT_LINE_COUNT, m_editLineCount);
	DDX_Radio(pDX, IDC_RADIO_WINDOWS, m_iKeyMap);
	DDX_Check(pDX, IDC_CHECK_CLEAR, m_boolClear);
	DDX_Text(pDX, IDC_EDIT_LINE_COUNT, m_strLineCount);
	//}}AFX_DATA_MAP

	if (pDX->m_bSaveAndValidate)
	{
		m_sEditLines = atoi( m_strLineCount );

		switch( m_iKeyMap )
		{
			case 1:
			{
				m_keyMap = keymapEmacs;
				break;
			}

			default:
			{
				m_keyMap = keymapWindows;
				break;
			}
		}
	}
}


BEGIN_MESSAGE_MAP( ChTextInputPrefsPage, ChPropertyBaseClass )
	//{{AFX_MSG_MAP(ChTextInputPrefsPage)
	ON_EN_UPDATE(IDC_EDIT_LINE_COUNT, OnUpdateEditLineCount)
	ON_BN_CLICKED(IDC_TINTIN_FILE, OnTintinFile)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/*----------------------------------------------------------------------------
	ChTextInputPrefsPage protected methods
----------------------------------------------------------------------------*/

void ChTextInputPrefsPage::DisplayTinTinName( const string& strName )
{
	CStatic*	pStatic = (CStatic*)GetDlgItem( IDC_STATIC_TINTIN_FILE );

	if (strName.GetLength())
	{
		string		strBrowserName( strName );

⌨️ 快捷键说明

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