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

📄 thememanager.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/* *  Roadnav *  ThemeManager.cpp * *  Copyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net> * *  This program is free software; you can redistribute it and/or *  modify it under the terms of version 2 of the GNU General Public License *  as published by the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */ ///////////////////////////////////////////////////////////////////////////////// \file////// Contains the ThemeManager class - a class to manage the color attribute/// themes./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include <wx/wx.h>#include "ThemeManager.h"//////////////////////////////////////////////////////////////////////////////////// Default constructor/////////////////////////////////////////////////////////////////////////////////ThemeManager::ThemeManager(){	m_ThemeUsage = AutoSwap;}//////////////////////////////////////////////////////////////////////////////////// Adds a new theme and associates it with map control data/////////////////////////////////////////////////////////////////////////////////void ThemeManager::AddTheme(const wxString& strTheme,MapAppearanceSettings & theme){	if (m_mapThemes.find(strTheme) == m_mapThemes.end())		m_mapThemes.insert( std::make_pair(strTheme, theme) );	else		UpdateTheme(strTheme, theme);}//////////////////////////////////////////////////////////////////////////////////// Updates a theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::UpdateTheme(const wxString& strTheme, MapAppearanceSettings & theme){	m_mapThemes[strTheme] = theme;}//////////////////////////////////////////////////////////////////////////////////// Returns a constant reference to a theme/////////////////////////////////////////////////////////////////////////////////const MapAppearanceSettings & ThemeManager::GetTheme(const wxString& strTheme) const{	std::map<wxString,MapAppearanceSettings>::const_iterator found;	found = m_mapThemes.find(strTheme);	wxASSERT(found != m_mapThemes.end() );	return (*found).second;}	//////////////////////////////////////////////////////////////////////////////////// Returns a reference to a theme/////////////////////////////////////////////////////////////////////////////////MapAppearanceSettings & ThemeManager::GetTheme(const wxString& strTheme){	std::map<wxString,MapAppearanceSettings>::iterator found;	found = m_mapThemes.find(strTheme);	wxASSERT(found != m_mapThemes.end() );	return (*found).second;}//////////////////////////////////////////////////////////////////////////////////// Removes a theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::RemoveTheme(const wxString& strTheme){	std::map<wxString,MapAppearanceSettings>::iterator found;	found = m_mapThemes.find(strTheme);	wxASSERT(found != m_mapThemes.end() );	m_mapThemes.erase(found);}//////////////////////////////////////////////////////////////////////////////////// Returns the number of themes/////////////////////////////////////////////////////////////////////////////////wxInt16 ThemeManager::GetThemeCount() const{	return m_mapThemes.size();}//////////////////////////////////////////////////////////////////////////////////// Renames a theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::RenameTheme(const wxString& strOldName,const wxString& strNewName){   MapAppearanceSettings theme = GetTheme(strOldName);   RemoveTheme(strOldName);   AddTheme(strNewName, theme);}//////////////////////////////////////////////////////////////////////////////////// Returns an array of theme names/////////////////////////////////////////////////////////////////////////////////wxArrayString ThemeManager::GetThemeNames() const{	wxArrayString themes;	std::map<wxString,MapAppearanceSettings>::const_iterator iter;	for (iter = m_mapThemes.begin(); iter != m_mapThemes.end(); iter++ )	{		themes.Add((*iter).first);	}		return themes;}//////////////////////////////////////////////////////////////////////////////////// Sets the theme usage/////////////////////////////////////////////////////////////////////////////////void ThemeManager::SetThemeUsage(ThemeManager::ThemeUsage usage){	m_ThemeUsage = usage;}//////////////////////////////////////////////////////////////////////////////////// Returns theme usage/////////////////////////////////////////////////////////////////////////////////ThemeManager::ThemeUsage ThemeManager::GetThemeUsage() const{	return m_ThemeUsage;}//////////////////////////////////////////////////////////////////////////////////// Sets the name of the nighttime theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::SetNightTheme(const wxString& strTheme){	m_strNightTheme = strTheme;}	//////////////////////////////////////////////////////////////////////////////////// Returns the name of the nighttime theme/////////////////////////////////////////////////////////////////////////////////wxString ThemeManager::GetNightThemeName() const{	return m_strNightTheme;}//////////////////////////////////////////////////////////////////////////////////// Returns the nighttime theme/////////////////////////////////////////////////////////////////////////////////const MapAppearanceSettings & ThemeManager::GetNightTheme() const{	return GetTheme(m_strNightTheme);}//////////////////////////////////////////////////////////////////////////////////// Sets the name of the daytime theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::SetDayTheme(const wxString& strTheme){	m_strDayTheme = strTheme;}//////////////////////////////////////////////////////////////////////////////////// Returns the name of the daytime theme/////////////////////////////////////////////////////////////////////////////////wxString ThemeManager::GetDayThemeName() const{	return m_strDayTheme;}//////////////////////////////////////////////////////////////////////////////////// Returns the daytime theme/////////////////////////////////////////////////////////////////////////////////const MapAppearanceSettings & ThemeManager::GetDayTheme() const{	return GetTheme(m_strDayTheme);}	//////////////////////////////////////////////////////////////////////////////////// Sets the name of the photo theme/////////////////////////////////////////////////////////////////////////////////void ThemeManager::SetPhotoTheme(const wxString& strTheme){	m_strPhotoTheme = strTheme;}//////////////////////////////////////////////////////////////////////////////////// Returns the name of the photo theme/////////////////////////////////////////////////////////////////////////////////wxString ThemeManager::GetPhotoThemeName() const{	return m_strPhotoTheme;}//////////////////////////////////////////////////////////////////////////////////// Returns the photo theme/////////////////////////////////////////////////////////////////////////////////const MapAppearanceSettings & ThemeManager::GetPhotoTheme() const{	return GetTheme(m_strPhotoTheme);}//////////////////////////////////////////////////////////////////////////////////// Loads the theme settings from the registry/config file/////////////////////////////////////////////////////////////////////////////////void ThemeManager::Load(wxConfigBase* pConfig){	wxString strOldPath = pConfig->GetPath();	pConfig->SetPath(wxT("Themes"));	int iUsage;	pConfig->Read(wxT("ThemeUsage"),&iUsage,0);	m_ThemeUsage = (ThemeUsage)iUsage;	pConfig->Read(wxT("NightTheme"),&m_strNightTheme,wxT("Default-Night"));	pConfig->Read(wxT("DayTheme"),  &m_strDayTheme,  wxT("Default-Day"));	pConfig->Read(wxT("PhotoTheme"),&m_strPhotoTheme,wxT("Default-Photo"));	wxString strGroup;	long key;	bool bContinue = pConfig->GetFirstGroup(strGroup,key);	while ( bContinue )	{		pConfig->SetPath(strGroup);		MapAppearanceSettings theme;				if (!theme.Load(pConfig))			AddTheme(strGroup,theme);		pConfig->SetPath(wxT(".."));		bContinue = pConfig->GetNextGroup(strGroup,key);	}	pConfig->SetPath(strOldPath);}//////////////////////////////////////////////////////////////////////////////////// Saves the theme settings to the registry/config file/////////////////////////////////////////////////////////////////////////////////void ThemeManager::Save(wxConfigBase* pConfig) const{	wxString strOldPath = pConfig->GetPath();	// remove all the existing theme entries	// (this is easier than trying to figure out if any were	//  renamed or deleted)	pConfig->DeleteGroup(wxT("Themes"));	// Creates a new group	pConfig->SetPath(wxT("Themes"));		pConfig->Write(wxT("ThemeUsage"),m_ThemeUsage);	// Save current theme selections	pConfig->Write(wxT("NightTheme"),m_strNightTheme);	pConfig->Write(wxT("DayTheme"), m_strDayTheme);	pConfig->Write(wxT("PhotoTheme"),m_strPhotoTheme);	// Save all the theme details	std::map<wxString,MapAppearanceSettings>::const_iterator iter;	for ( iter = m_mapThemes.begin(); iter != m_mapThemes.end(); iter++ )	{		const wxString& strThemeName = (*iter).first;		const MapAppearanceSettings & theme = (*iter).second;		pConfig->SetPath(strThemeName);		theme.Save(pConfig);		pConfig->SetPath(wxT("..")); // back up to the Themes level	}	pConfig->SetPath(strOldPath);}

⌨️ 快捷键说明

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