Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Internet Explorer AdBlock

, 17 Jan 2008 GPL3
Internet Explorer AdBlock Add-on
ieadblock_src.zip
IE AdBlockPS
IE AdBlockps.def
IE AdBlock
AdBlockBand.rgs
AdBlockBHO.rgs
bin
XListCtrlSSDU.lib
XListCtrlSSRU.lib
IE AdBlock.def
IE AdBlock.rgs
res
bmpToolbar.bmp
checkboxes.bmp
icoSettings.ico
XListCtrl
checkboxes.bmp
//*********************************************************************
// INCLUDES
//*********************************************************************

#include "stdafx.h"
#include "SettingsSheet.h"

//*********************************************************************
// MESSAGE MAP
//*********************************************************************

BEGIN_MESSAGE_MAP(CSettingsSheet, CPropertySheet)
END_MESSAGE_MAP()

//*********************************************************************
// CONSTRUCTOR & DESTRUCTOR
//*********************************************************************

IMPLEMENT_DYNAMIC(CSettingsSheet, CPropertySheet)

//=====================================================================

CSettingsSheet::CSettingsSheet(CAdList * pBlackList, CAdList * pWhiteList)
{
	// Create pages
	m_pGeneral = new CSettingsGeneral();
	m_pBlackList = new CSettingsList(pBlackList);
	m_pWhiteList = new CSettingsList(pWhiteList);
	m_pPerformance = new CSettingsPerformance();
	m_pAbout = new CSettingsAbout();

	// Add pages
	AddPage(m_pGeneral);
	AddPage(m_pBlackList);
	AddPage(m_pWhiteList);
	AddPage(m_pPerformance);
	AddPage(m_pAbout);
}

//=====================================================================

CSettingsSheet::~CSettingsSheet()
{
	// Destroy pages
	delete m_pGeneral;
	m_pGeneral = NULL;
	delete m_pBlackList;
	m_pBlackList = NULL;
	delete m_pWhiteList;
	m_pWhiteList = NULL;
	delete m_pPerformance;
	m_pPerformance = NULL;
	delete m_pAbout;
	m_pAbout = NULL;
}

//*********************************************************************
// PUBLIC FUNCTIONS
//*********************************************************************

BOOL CSettingsSheet::OnInitDialog()
{
	// Declare variables
	CString sTemp = _T("");
	CLanguage * pLanguage = CLanguage::Instance();

	// Call original function
	CPropertySheet::OnInitDialog();

	// Set title
#ifdef DEBUG
	sTemp.Format(pLanguage->GetString(IDS_SETTINGS_TITLE) + _T(" (debug mode)"),
		pLanguage->GetString(IDS_PROJNAME));
#else
	sTemp.Format(pLanguage->GetString(IDS_SETTINGS_TITLE),
		pLanguage->GetString(IDS_PROJNAME));
#endif
	SetWindowText(sTemp);

	// Set title of tabs
	SetTabTitle(m_pGeneral, pLanguage->GetString(IDS_GENERAL_TITLE));
	SetTabTitle(m_pBlackList, pLanguage->GetString(IDS_BLACKLIST_TITLE));
	SetTabTitle(m_pWhiteList, pLanguage->GetString(IDS_WHITELIST_TITLE));
	SetTabTitle(m_pPerformance, pLanguage->GetString(IDS_PERFORMANCE_TITLE));
	SetTabTitle(m_pAbout, pLanguage->GetString(IDS_ABOUT_TITLE));

	// Set icon
	SetIcon(AfxGetApp()->LoadIcon(IDI_SETTINGS), false);
	SetIcon(AfxGetApp()->LoadIcon(IDI_SETTINGS), true);

	// Return TRUE unless you want to set focus to a control
	return TRUE;
}

//=====================================================================

void CSettingsSheet::EnablePage(int iPage, BOOL bEnable /* = TRUE */)
{
	// If we want to enable the page
	if (bEnable)
	{
		// Remove the index from the map
		m_mapDisabledPages.RemoveKey(iPage);

		// take out " - Disabled" from tab label
		CTabCtrl* pTab = GetTabControl();
		ASSERT (pTab);
		TC_ITEM ti;
		TCHAR szText[100];
		ti.mask = TCIF_TEXT;
		ti.pszText = szText;
		ti.cchTextMax = 100;
		VERIFY(pTab->GetItem(iPage, &ti));
		TCHAR * pFound = _tcsstr(szText, _T(" - Disabled"));
		if (pFound)
		{
			*pFound = _T('\0');
			VERIFY(pTab->SetItem(iPage, &ti));
		}
	}
	else
	{
		// Add the index to the map
		m_mapDisabledPages.SetAt(iPage, iPage);

		// add " - Disabled" to tab label
		CTabCtrl* pTab = GetTabControl();
		ASSERT (pTab);
		TC_ITEM ti;
		TCHAR szText[100];
		ti.mask = TCIF_TEXT;
		ti.pszText = szText;
		ti.cchTextMax = 100;
		VERIFY(pTab->GetItem(iPage, &ti));
		lstrcat(szText, _T(" - Disabled"));
		VERIFY(pTab->SetItem(iPage, &ti));
	}
}

//*********************************************************************
// PRIVATE FUNCTIONS
//*********************************************************************

BOOL CSettingsSheet::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
{
	// Declare variables
	NMHDR* pnmh = (NMHDR*)lParam;

	switch (pnmh->code)
	{
	case TCN_SELCHANGING:
		// Save the current page index
		m_iLastActive = GetActiveIndex();
		// Tab has been changed
		break;

	case TCN_SELCHANGE:
		// Get the current page index
		int iCurrentPage = GetActiveIndex();

		// If current page is in our map of disabled pages
		if (m_mapDisabledPages.Lookup(iCurrentPage, iCurrentPage))
		{
			// Activate the previous page
			PostMessage(PSM_SETCURSEL, m_iLastActive);
		}
		break;
	}

	// Call original function
	return CPropertySheet::OnNotify(wParam, lParam, pResult);
}

//=====================================================================

void CSettingsSheet::SetTabTitle(CPropertyPage * pPage, CString sTitle)
{
	// Declare variables
	TC_ITEM tcItem;
	int iIndex = 0;

	// Set item properties
	tcItem.mask = TCIF_TEXT;
	tcItem.pszText = (LPWSTR)((LPCTSTR)sTitle);

	// Check if a valid page is passed
	if (pPage == NULL)
	{
		// No, exit function
		return;
	}

	// Get index of current tab in the parent
	iIndex = GetPageIndex(pPage);

	// Change correct item
	GetTabControl()->SetItem(iIndex, &tcItem);
}

//=====================================================================

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.
 
I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.
 
I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 17 Jan 2008
Article Copyright 2008 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid