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

📄 preferencespagethemes.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/* *  Roadnav *  PreferencesPageThemes.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 Themes page of the preferences dialog box./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H#  include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#pragma warning(disable: 4800)#endif#include <wx/wx.h>#include "PreferencesPageThemes.h"#include "ThemeManager.h"#include "EditThemeDialog.h"//////////////////////////////////////////////////////////////////////////////////// IDs for PreferencesPageThemes.cpp/////////////////////////////////////////////////////////////////////////////////enum{	idThemes,	idAdd,	idEdit,	idRemove,	idNightTheme,	idDayTheme,	idPhotoTheme};//////////////////////////////////////////////////////////////////////////////////// PreferencesPageThemes event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(PreferencesPageThemes, wxPanel)	EVT_BUTTON(idAdd,PreferencesPageThemes::OnAdd)	EVT_BUTTON(idEdit,PreferencesPageThemes::OnEdit)	EVT_BUTTON(idRemove,PreferencesPageThemes::OnRemove)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// PreferencesPageThemes constructor - create and initialize controls/////////////////////////////////////////////////////////////////////////////////PreferencesPageThemes::PreferencesPageThemes(wxWindow *parent, IMapControlData * pMapControlData, ThemeManager * pThemeManager)             : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){	m_pMapControlData = pMapControlData;	m_pParentThemeManager = pThemeManager;		m_ThemeManager = *m_pParentThemeManager;    wxFlexGridSizer* psizerGrid = new wxFlexGridSizer(1, 3, 0, 0);		//////////////////////////////////////////////////////////////////////////	// List of themes	//////////////////////////////////////////////////////////////////////////    wxBoxSizer* psizerThemeList = new wxBoxSizer(wxVERTICAL);	psizerThemeList->Add( new wxStaticText(this, -1, wxT("Manage Themes")), 0, wxALL, 5 );    m_pctlThemeList = new wxListBox(this, idThemes, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE|wxLB_SORT);	psizerThemeList->Add(m_pctlThemeList, 1, wxALL|wxEXPAND, 5);	psizerGrid->Add(psizerThemeList, 1, wxEXPAND, 0);	//////////////////////////////////////////////////////////////////////////	// Command buttons	//////////////////////////////////////////////////////////////////////////	wxBoxSizer* psizerCommandButtons = new wxBoxSizer(wxVERTICAL);	psizerCommandButtons->Add(20,20,0,wxALL,5);    psizerCommandButtons->Add( new wxButton(this, idAdd, wxT("Add...")), 0, wxALL, 5);    psizerCommandButtons->Add( new wxButton(this, idEdit, wxT("Edit...")), 0, wxALL, 5);    psizerCommandButtons->Add( new wxButton(this, idRemove, wxT("Remove")), 0, wxALL, 5);	psizerGrid->Add(psizerCommandButtons, 1, wxEXPAND, 0);	//////////////////////////////////////////////////////////////////////////	// Active themes	//////////////////////////////////////////////////////////////////////////	wxString strings(wxT("Default"));	wxBoxSizer* psizerActiveThemes = new wxBoxSizer(wxVERTICAL);	psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Nighttime Theme")), 0, wxALL, 5);	m_pctlNightTheme = new wxComboBox(this,idNightTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY);	psizerActiveThemes->Add( m_pctlNightTheme, 1, wxALL | wxEXPAND, 5);	psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Daytime Theme")), 0, wxALL, 5);	m_pctlDayTheme = new wxComboBox(this,idDayTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY);	psizerActiveThemes->Add( m_pctlDayTheme, 1, wxALL | wxEXPAND, 5);		psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Aerial Photo Theme")), 0, wxALL, 5);		m_pctlPhotoTheme = new wxComboBox(this,idPhotoTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY);	psizerActiveThemes->Add( m_pctlPhotoTheme, 1, wxALL | wxEXPAND, 5);	wxString strChoices[] = {wxString(wxT("Swap at sunrise/sunset")),wxString(wxT("Nighttime Only")),wxString(wxT("Daytime Only"))};	m_pctlThemeUsage = new wxRadioBox(this,-1,wxT("Theme Usage"),wxDefaultPosition,wxDefaultSize,3,strChoices,1,wxRA_SPECIFY_COLS);	psizerActiveThemes->Add( m_pctlThemeUsage, 0, wxALL, 5);	psizerGrid->Add(psizerActiveThemes, 1, wxEXPAND, 0);	//////////////////////////////////////////////////////////////////////////	// psizerWnd just adds a border to psizerGrid	//////////////////////////////////////////////////////////////////////////		wxBoxSizer* psizerWnd = new wxBoxSizer(wxVERTICAL);	psizerWnd->Add(		psizerGrid,		0,		wxALL | wxGROW,		10	);		//////////////////////////////////////////////////////////////////////////	// Set up the sizer	//////////////////////////////////////////////////////////////////////////	m_pctlThemeList->SetFocus();	psizerWnd->Fit(this);	SetSizer(psizerWnd);	Layout();	psizerWnd->SetSizeHints(this);	//////////////////////////////////////////////////////////////////////////	// Fill up the theme lists	//////////////////////////////////////////////////////////////////////////	wxArrayString strThemes = m_ThemeManager.GetThemeNames();		m_pctlThemeList->Append(strThemes);	m_pctlNightTheme->Append(strThemes);	m_pctlDayTheme->Append(strThemes);	m_pctlPhotoTheme->Append(strThemes);		//////////////////////////////////////////////////////////////////////////	// Make the initialize selections	//////////////////////////////////////////////////////////////////////////	if (strThemes.Count() >= 1)		m_pctlThemeList->SetSelection(0);			m_pctlNightTheme->SetStringSelection( m_ThemeManager.GetNightThemeName() );	m_pctlDayTheme->SetStringSelection( m_ThemeManager.GetDayThemeName() );	m_pctlPhotoTheme->SetStringSelection( m_ThemeManager.GetPhotoThemeName() );	m_pctlThemeUsage->SetSelection( m_ThemeManager.GetThemeUsage() );}//////////////////////////////////////////////////////////////////////////////////// Ok was pressed .. save the settings/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnOk(wxCommandEvent& event){	m_ThemeManager.SetNightTheme( m_pctlNightTheme->GetStringSelection() );	m_ThemeManager.SetDayTheme( m_pctlDayTheme->GetStringSelection() );	m_ThemeManager.SetPhotoTheme( m_pctlPhotoTheme->GetStringSelection() );	m_ThemeManager.SetThemeUsage( (ThemeManager::ThemeUsage)m_pctlThemeUsage->GetSelection() );	// apply changes	*m_pParentThemeManager = m_ThemeManager;}//////////////////////////////////////////////////////////////////////////////////// Add was pressed .. create a new theme and edit it/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnAdd(wxCommandEvent& event){	// Don't store the theme in the theme manager until	// after it has been edited. Give the user an opportunity	// to change it's name.	//	// After edited, need to update combo boxes	int iIndex;	MapAppearanceSettings cNewTheme = m_ThemeManager.GetTheme(wxT("Default-Day"));	wxString strNewTheme = wxString::Format(wxT("Theme%d"), m_ThemeManager.GetThemeCount() + 1);	if (EditTheme(strNewTheme, cNewTheme) != wxID_OK)		return;	m_ThemeManager.AddTheme(strNewTheme, cNewTheme);	RefreshComboBoxes();	// make the added theme the selected theme	iIndex = m_pctlThemeList->FindString(strNewTheme);	wxASSERT(iIndex >= 0);	m_pctlThemeList->SetSelection(iIndex);}//////////////////////////////////////////////////////////////////////////////////// Edit was pressed .. edit the selected theme/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnEdit(wxCommandEvent& event){	wxString strOldThemeName = m_pctlThemeList->GetStringSelection();	wxString strNewThemeName = strOldThemeName;		if (EditTheme(strNewThemeName, m_ThemeManager.GetTheme(strOldThemeName)) != wxID_OK)		return;	if (strNewThemeName != strOldThemeName)	{		// the theme was renamed		m_ThemeManager.RenameTheme(strOldThemeName, strNewThemeName);		RefreshComboBoxes(strOldThemeName, strNewThemeName);	}}//////////////////////////////////////////////////////////////////////////////////// Remove was pressed .. remove the selected theme, provided it is not the/// last one./////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnRemove(wxCommandEvent& event){	wxString strTheme = m_pctlThemeList->GetStringSelection();	if (m_pctlThemeList->GetCount() < 2)	{		wxMessageBox(wxT("You cannot delete the last theme."), wxT("Error"), wxICON_ERROR | wxOK);		return;	}	if (wxMessageBox(	wxString::Format(wxT("Are you sure you want to permanently delete %s?"),strTheme.c_str()), 						wxT("Confirm Deletion"), 						wxYES_NO | wxICON_QUESTION, 						this) != wxYES)		return;	m_ThemeManager.RemoveTheme(strTheme);	RefreshComboBoxes();}//////////////////////////////////////////////////////////////////////////////////// Edit the theme/////////////////////////////////////////////////////////////////////////////////int PreferencesPageThemes::EditTheme(wxString& strTheme, MapAppearanceSettings & theme){	int iRtn;	EditThemeDialog dlg(this, strTheme, theme, m_pMapControlData);		iRtn = dlg.ShowModal();		if (iRtn == wxID_OK)	{		theme = dlg.GetTheme();		strTheme = dlg.GetThemeName();	}		return iRtn;}//////////////////////////////////////////////////////////////////////////////////// The list of theme names has changed... refresh all the combo boxes/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::RefreshComboBoxes(const wxString & strRenameFrom, const wxString & strRenameTo){	// Get current selection	wxString strNightTheme		= m_pctlNightTheme->GetStringSelection();	wxString strDayTheme		= m_pctlDayTheme->GetStringSelection();	wxString strPhotoTheme		= m_pctlPhotoTheme->GetStringSelection();	wxString strSelectedTheme	= m_pctlThemeList->GetStringSelection();	int iSel;		if (strNightTheme == strRenameFrom)		strNightTheme = strRenameTo;	if (strDayTheme == strRenameFrom)		strDayTheme = strRenameTo;	if (strPhotoTheme == strRenameFrom)		strPhotoTheme = strRenameTo;	if (strSelectedTheme == strRenameFrom)		strSelectedTheme = strRenameTo;	m_pctlThemeList->Clear();	m_pctlNightTheme->Clear();	m_pctlDayTheme->Clear();	m_pctlPhotoTheme->Clear();	wxArrayString strThemes = m_ThemeManager.GetThemeNames();	m_pctlThemeList->Append(strThemes);	m_pctlNightTheme->Append(strThemes);	m_pctlDayTheme->Append(strThemes);	m_pctlPhotoTheme->Append(strThemes);		if (strThemes.GetCount() == 0)		return;	// Restore current selection	iSel = m_pctlThemeList->FindString(strSelectedTheme);	if (iSel >= 0)		m_pctlThemeList->SetSelection(iSel);	else		m_pctlThemeList->SetSelection(0);			iSel = m_pctlNightTheme->FindString(strNightTheme);	if (iSel >= 0)		m_pctlNightTheme->SetSelection(iSel);	else		m_pctlNightTheme->SetSelection(0);			iSel = m_pctlDayTheme->FindString(strDayTheme);	if (iSel >= 0)		m_pctlDayTheme->SetSelection(iSel);	else		m_pctlDayTheme->SetSelection(0);	iSel = m_pctlPhotoTheme->FindString(strPhotoTheme);	if (iSel >= 0)		m_pctlPhotoTheme->SetSelection(iSel);	else		m_pctlPhotoTheme->SetSelection(0);}

⌨️ 快捷键说明

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