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

📄 symbolpropertiesgeneralpage.cpp

📁 一个vc中管理资源文件ID的插件
💻 CPP
字号:
/************************************************************************
 *
 *                 Resource ID Organiser Utility Library
 *
 *       (c) Copyright 2000 by Andy Metcalfe (andy.metcalfe@lineone.net)
 *                         All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Filename    : SymbolPropertiesGeneralPage.cpp
 *
 *  Description : CSymbolPropertiesGeneralPage - property page class
 *                
 *  Compiler    : Microsoft Visual C++ 6.0, Service Pack 3 or 4
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 98/NT
 *
 *  NOTE:
 *
 *    This software is provided "as is" free for personal use. All
 *    title and copyrights in and to the software, including but not
 *    limited to any images, text, etc. incorporated into it, are
 *    owned by Andy Metcalfe, except where acknowledged otherwise.
 *
 *    Your may freely to use this code in your own products, PROVIDED
 *    this notice is not removed or modified.
 *
 *
 *    Visit http://www.resorg.co.uk for latest updates
 *
 ************************************************************************
 *
 *   MODIFICATION HISTORY:
 *
 *           This is a controlled document. See project configuration
 *           control tool for latest version and full version history.
 *
 *    $Archive: /Projects/AddIns/ResOrg/ResOrgUtils/SymbolPropertiesGeneralPage.cpp $
 *   $Revision: 8 $
 *       $Date: 23/04/01 21:15 $
 *     $Author: Andy $
 *
 *    $History: SymbolPropertiesGeneralPage.cpp $
 * 
 * *****************  Version 8  *****************
 * User: Andy         Date: 23/04/01   Time: 21:15
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Added "Fix Conflict" button
 * 2.  A warning message is now displayed when a symbol is made read-only
 * 
 * *****************  Version 7  *****************
 * User: Andy         Date: 2/04/01    Time: 17:26
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Added a rich edit control (and associated icon) to warn of symbol
 * name/value conflicts
 * 2.  Improved validation routines and messages
 * 
 * *****************  Version 6  *****************
 * User: Andy         Date: 27/03/01   Time: 15:22
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Added validation of symbol names
 * 2.  When the symbol value changes, the parent property sheet is
 * notified to update the "Conflicts" page
 * 
 * *****************  Version 5  *****************
 * User: Andy         Date: 9/03/01    Time: 7:06
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * Make the warning prompt when a symbol name is changed optional, so it
 * can be disabled when the dialog is used to edit the properties of a
 * symbol being added
 * 
 * *****************  Version 4  *****************
 * User: Andy         Date: 17/02/01   Time: 7:05
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 * 1.  Converted to proeprty page
 * 2.  Added "type" icon
 * 3.  Added support for read only symbols
 * 4.  The "type" control is now set automatically when the symbol name is
 * changed
 * 
 * *****************  Version 3  *****************
 * User: Andy         Date: 29/11/00   Time: 18:38
 * Updated in $/Projects/AddIns/ResOrg/ResOrgUtils
 *  Added file banners
 *
 * $Nokeywords: $
 *
 ************************************************************************/

// SymbolPropertiesGeneralPage.cpp : implementation file
//

#include "StdAfx.h"
#include "ResOrgUtils_Priv.h"

#include "SymbolPropertiesGeneralPage.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


// Registered message definitions
const UINT WM_SYM_CHANGING	= ::RegisterWindowMessage( _T("SymbolChanging") );


/////////////////////////////////////////////////////////////////////////////
// CSymbolPropertiesGeneralPage property page

CSymbolPropertiesGeneralPage::CSymbolPropertiesGeneralPage(void)
	: CSymbolPropertiesGeneralPage_BASE(CSymbolPropertiesGeneralPage::IDD)
{
	m_pSymbols		= NULL;
	m_pSymbol		= NULL;

	//{{AFX_DATA_INIT(CSymbolPropertiesGeneralPage)
	m_sName					= _T("");
	m_sType					= _T("");
	m_uValue				= 0;
	m_bReadOnly				= FALSE;
	//}}AFX_DATA_INIT

	m_uIconID				= 0;

	m_sSavedName			= _T("");

	m_bWarnOnSymbolChanges = Options.WarnOnSymbolChanges();

	AfxInitRichEdit();		// Just in case nobody else has...
}


CSymbolPropertiesGeneralPage::~CSymbolPropertiesGeneralPage(void)
{
}


void CSymbolPropertiesGeneralPage::DoDataExchange(CDataExchange* pDX)
{
	CSymbolPropertiesGeneralPage_BASE::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSymbolPropertiesGeneralPage)
	DDX_Control(pDX,		IDC_SYM_ICON,				m_ctrlIcon);
	DDX_Control(pDX,		IDC_SYM_WARNING,			m_ctrlWarning);
	DDX_Control(pDX,		IDC_SYM_WARNING_ICON,		m_ctrlWarningIcon);
	DDX_Text(pDX,			IDC_SYM_TYPE,				m_sType);
	DDX_Text(pDX,			IDC_SYM_VALUE,				m_uValue);
	DDV_MinMaxUInt(pDX,									m_uValue, 1, 65535);
	DDX_Check(pDX,			IDC_SYM_READONLY,			m_bReadOnly);
	//}}AFX_DATA_MAP

	DDX_SymbolName(pDX,		IDC_SYM_NAME,				m_sName);
	DDV_SymbolName(pDX,									m_sName);
}


BEGIN_MESSAGE_MAP(CSymbolPropertiesGeneralPage, CSymbolPropertiesGeneralPage_BASE)
	//{{AFX_MSG_MAP(CSymbolPropertiesGeneralPage)
	ON_COMMAND(				IDC_SYM_NAME,				OnCmdSymbolName)
	ON_COMMAND(				IDC_SYM_VALUE,				OnCmdSymbolValue)
	ON_COMMAND(				IDC_SYM_READONLY,			OnCmdReadOnly)
	ON_BN_CLICKED(			IDC_SYM_FIX_CONFLICT,		OnClickedFixConflict)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


BOOL CSymbolPropertiesGeneralPage::OnInitDialog(void)
{
	CSymbolPropertiesGeneralPage_BASE::OnInitDialog();

	// Set the background colour of the rich edit control to the
	// same as the dialog, so nobody realises what it really is....
	m_ctrlWarning.SetBackgroundColor(FALSE, ::GetSysColor(COLOR_3DFACE) );
	m_ctrlWarning.SetFont( GetFont() );

	m_sSavedName = m_sName;

	OnCmdSymbolName();		// Set the type and icon, and
							// check for name conflicts
	OnCmdSymbolValue();		// Check for value conflicts
	OnCmdReadOnly();		// Set available controls

	return TRUE;
}


BOOL CSymbolPropertiesGeneralPage::OnKillActive(void)
{
	// Force the "Conflicts" page to update before losing focus
	GetParent()->SendMessage(	WM_SYM_CHANGING,
								m_uValue,
								(LPARAM)(LPCTSTR)m_sName);

	return CSymbolPropertiesGeneralPage_BASE::OnKillActive();
}


void CSymbolPropertiesGeneralPage::OnOK(void)
{
	// If the option is enabled, show a warning
	// if the symbol name has been changed
	if (m_bWarnOnSymbolChanges && (m_sSavedName != m_sName) )
	{
		CNGMessageBox dlg;
		dlg.SetMsgEx( MAKEINTRESOURCE(IDP_SYM_RENAME_WARNING), _T("RTF") );
		dlg.SetRtf();
		dlg.SetStandardIcon(IDI_EXCLAMATION);
		dlg.AddButton(IDYES, FALSE, FALSE, _T("Yes") );
		dlg.AddButton(IDNO, TRUE, TRUE, _T("No") );

		if (IDYES != dlg.DoModal())
		{
			m_sName = m_sSavedName;
			UpdateData(FALSE);

			return;
		}
	}
	CSymbolPropertiesGeneralPage_BASE::OnOK();
}


/////////////////////////////////////////////////////////////////////////////
// CSymbolPropertiesGeneralPage operations

BOOL CSymbolPropertiesGeneralPage::Initialise(CResourceSymbolBuffer* pSymbols)
{
	m_pSymbols = pSymbols;

	return (m_pSymbols !=  NULL);
}


BOOL CSymbolPropertiesGeneralPage::SetSymbol(CResourceSymbol* pSymbol)
{
	m_pSymbol = pSymbol;

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CSymbolPropertiesGeneralPage implementation

BOOL CSymbolPropertiesGeneralPage::SetTypeIcon(UINT uIconID)
{
	if ( (uIconID != 0) && ::IsWindow(m_ctrlIcon.m_hWnd) )
	{
		m_uIconID = uIconID;

		HICON hIcon = AfxGetApp()->LoadIcon(m_uIconID);
		ASSERT(hIcon != NULL);

		m_ctrlIcon.SetIcon(hIcon);

		return TRUE;
	}
	return FALSE;
}


void CSymbolPropertiesGeneralPage::DDX_SymbolName(CDataExchange* pDX,
												  UINT uIDC,
												  CString& rsSymbolName)
{
	if (pDX->m_bSaveAndValidate)
	{
		CString sNewSymbolName;

		::DDX_Text(pDX, uIDC, sNewSymbolName);

		// Remove whitespace before validating
		sNewSymbolName.TrimLeft();
		sNewSymbolName.TrimRight();

		// Now work out whether it's valid
		if (CResourceSymbol::IsValidName(sNewSymbolName) )
		{
			rsSymbolName = sNewSymbolName;
		}
		else
		{
			// Nope - alert the user
			CNGMessageBox dlg;

			dlg.FormatMsgEx(MAKEINTRESOURCE(IDP_SYM_NAME_INVALID),
							_T("RTF"),
							sNewSymbolName);
			dlg.SetRtf();
			dlg.SetStandardIcon(IDI_ERROR);
			dlg.AddButton(IDOK, TRUE, TRUE, _T("OK") );

			dlg.DoModal();

			pDX->Fail();
		}
	}
	else
	{
		::DDX_Text(pDX, uIDC, rsSymbolName);
	}
}


void CSymbolPropertiesGeneralPage::DDV_SymbolName(CDataExchange* pDX,
												  CString& rsSymbolName)
{
	if (pDX->m_bSaveAndValidate)
	{
		if ( (m_pSymbol != NULL) && !IsNameUnique(m_pSymbol, rsSymbolName) )
		{
			CNGMessageBox dlg;
			dlg.SetMsgEx( MAKEINTRESOURCE(IDP_SYM_NAME_WARNING), _T("RTF") );
			dlg.SetRtf();
			dlg.SetStandardIcon(IDI_EXCLAMATION);
			dlg.AddButton(IDOK, TRUE, TRUE, _T("OK") );

			dlg.DoModal();

			pDX->Fail();
		}
	}
}


BOOL CSymbolPropertiesGeneralPage::IsNameUnique(CResourceSymbol* pSymbol,
												const CString& sName) const
{
	BOOL bUnique = TRUE;

	if ( (m_pSymbols != NULL) && (pSymbol != NULL) )
	{
		CResourceSymbolList listSymbols;
		m_pSymbols->GetSymbols(sName, listSymbols);

		POSITION pos = listSymbols.GetHeadPosition();
		while (pos != NULL)
		{
			CResourceSymbol* pNextSymbol = listSymbols.GetNext(pos);
			if (pNextSymbol != NULL)
			{
				if (pNextSymbol != pSymbol)
				{
					bUnique = FALSE;
					break;
				}
			}
		}
	}
	return bUnique;
}


BOOL CSymbolPropertiesGeneralPage::IsValueUnique(CResourceSymbol* pSymbol,
												 UINT uValue) const
{
	BOOL bUnique = TRUE;

	if ( (NULL != m_pSymbols) && (NULL != pSymbol) )
	{
		CResourceSymbolList listSymbols;
		m_pSymbols->GetSymbols(uValue, listSymbols);

		POSITION pos = listSymbols.GetHeadPosition();
		while (pos != NULL)
		{
			CResourceSymbol* pNextSymbol = listSymbols.GetNext(pos);
			if (pNextSymbol != NULL)
			{
				if (pNextSymbol != pSymbol)
				{
					bUnique = FALSE;
					break;
				}
			}
		}
	}
	return bUnique;
}

BOOL CSymbolPropertiesGeneralPage::SetWarningText(	const CString& sWarning,
													LPCTSTR pszIconID /*= NULL*/)
{
	if (!sWarning.IsEmpty() )
	{
		// Set the icon
		m_ctrlWarningIcon.SetIcon(AfxGetApp()->LoadStandardIcon(pszIconID));

		// Set the text
		m_ctrlWarning.SetRTF(sWarning);

		// Hide the current selection
		// Note that for this to work the control must NOT
		// have the "Tab Stop" property set in the resource
		// editor...this took me AGES to figure out...
		m_ctrlWarning.HideSelection(TRUE, TRUE);

		m_ctrlWarningIcon.ShowWindow(TRUE);
		m_ctrlWarning.ShowWindow(TRUE);

		return TRUE;
	}
	m_ctrlWarningIcon.ShowWindow(FALSE);
	m_ctrlWarning.ShowWindow(FALSE);

	return FALSE;
}


void CSymbolPropertiesGeneralPage::CheckForConflicts(void)
{
	if (!IsNameUnique(m_pSymbol, m_sName) )
	{
		SetWarningText( ::LoadRtfString(IDS_SYM_NAME_CONFLICT_CAPTION),
						IDI_ERROR);

		ShowDlgControl(IDC_SYM_FIX_CONFLICT, FALSE);
	}
	else if (!IsValueUnique(m_pSymbol, m_uValue) )
	{
		SetWarningText( ::LoadRtfString(IDS_SYM_VALUE_CONFLICT_CAPTION),
						IDI_WARNING);

		ShowDlgControl(IDC_SYM_FIX_CONFLICT, TRUE);
	}
	else
	{
		SetWarningText( _T("") );

		ShowDlgControl(IDC_SYM_FIX_CONFLICT, FALSE);
	}

	// Inform the parent that the symbol is changing
	// This is used to update the "Conflicts" page
	GetParent()->SendMessage(	WM_SYM_CHANGING,
								m_uValue,
								(LPARAM)(LPCTSTR)m_sName);
}


/////////////////////////////////////////////////////////////////////////////
// CSymbolPropertiesGeneralPage message handlers

void CSymbolPropertiesGeneralPage::OnCmdSymbolName(void)
{
	// Update type control and icon
	int eType = SymbolTypes.GetType(m_sName);

	// Set the icon...
	SetTypeIcon( SymbolTypes.GetIconID(eType) );

	// ...and the displayed description
	m_sType = SymbolTypes.GetTypeName(eType);
	ASSERT(!m_sType.IsEmpty());

	UpdateData(FALSE);

	// Check for name conflicts...
	CheckForConflicts();
}


void CSymbolPropertiesGeneralPage::OnCmdSymbolValue(void)
{
	CheckForConflicts();
}


void CSymbolPropertiesGeneralPage::OnCmdReadOnly(void)
{
	ShowDlgControl(		IDC_SYM_READONLY_CAUTION,	m_bReadOnly);

	EnableDlgControl(	IDC_SYM_NAME,				!m_bReadOnly);
	EnableDlgControl(	IDC_SYM_TYPE,				!m_bReadOnly);
	EnableDlgControl(	IDC_SYM_VALUE,				!m_bReadOnly);
	EnableDlgControl(	IDC_SYM_FIX_CONFLICT,		!m_bReadOnly);
}


void CSymbolPropertiesGeneralPage::OnClickedFixConflict(void)
{
	BOOL bFailed = FALSE;

	UINT uValue = m_uValue;
	while (!IsValueUnique(m_pSymbol, uValue) )
	{
		uValue++;
		if (uValue >= IDC_STATIC)
		{
			bFailed = TRUE;
			break;		// Can't fix this one
		}
	}
	if (!bFailed)
	{
		m_uValue = uValue;
		UpdateData(FALSE);

		CheckForConflicts();
	}
	else
	{
		AfxMessageBox(	IDP_SYM_FIX_CONFLICT_FAILED,
						MB_OK | MB_ICONEXCLAMATION);
	}
}

⌨️ 快捷键说明

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