📄 countydialog.cpp
字号:
/* * Roadnav * CountyDialog.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/// /// Dialog box allowing a user to select one or more counties./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H# include <config.h>#endif#include <wx/wx.h>#include "CountyDialog.h"#include "libroadnav/MapCounty.h"using namespace std;//////////////////////////////////////////////////////////////////////////////////// CountyDialog event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(CountyDialog, wxDialog) EVT_BUTTON(wxID_OK, CountyDialog::OnOk)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief CountyDialog constructor - create controls and initialize them/////////////////////////////////////////////////////////////////////////////////CountyDialog::CountyDialog(wxWindow *parent, wxFont * pFont, vector<wxString> vHighlight) : wxDialog(parent, -1, wxString(_T("Select Counties")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER){ vector<wxString>::iterator i; unsigned int iIndex; vector<wxString> vCounties; wxArrayString asCounties; // Use supplied font if (pFont) SetFont(*pFont); // Get list of all county names vCounties = GetCountyNames(); wxBoxSizer *sizerWnd = new wxBoxSizer(wxVERTICAL); m_ctlCounties = new wxListCtrl(this, -1, wxDefaultPosition, wxSize(500, 400), wxLC_LIST ); // add each county name to asCounties for (i = vCounties.begin(); i != vCounties.end(); i++) asCounties.Add(*i); // sort county names asCounties.Sort(); // put into control for (iIndex = 0; iIndex < asCounties.Count(); iIndex++) { wxString strThis; bool bHighlightThis; vector<wxString>::iterator iSearch; strThis = asCounties[iIndex]; bHighlightThis = false; // check if it's supposed to be highlighted for (iSearch = vHighlight.begin(); iSearch != vHighlight.end() && !bHighlightThis; iSearch++) if (*iSearch == strThis) bHighlightThis = true; // add to list control m_ctlCounties->InsertItem(iIndex, strThis); // highlight if necessary if (bHighlightThis) { wxColour clrBackground; wxColour clrForeground; wxColour clrHighlight; clrForeground = m_ctlCounties->GetForegroundColour(); clrBackground = m_ctlCounties->GetBackgroundColour(); // calculate highlight color as halfway between foreground and background color clrHighlight.Set( clrForeground.Red() / 2 + clrBackground.Red() / 2, clrForeground.Green() / 2 + clrBackground.Green() / 2, clrForeground.Blue() / 2 + clrBackground.Blue() / 2); m_ctlCounties->SetItemTextColour(iIndex, clrHighlight); } } sizerWnd->Add(m_ctlCounties, 1, wxGROW | wxALL, 5); wxBoxSizer *sizerBottom = new wxBoxSizer(wxHORIZONTAL); wxButton * btnOk = new wxButton(this, wxID_OK, _T("&OK")); sizerBottom->Add(btnOk, 0, wxALL, 5); wxButton * btnCancel = new wxButton(this, wxID_CANCEL, _T("&Cancel")); sizerBottom->Add(btnCancel, 0, wxALL, 5); sizerWnd->Add(sizerBottom, 0, wxALIGN_CENTER | wxALL, 5); SetAutoLayout(TRUE); SetSizer(sizerWnd); sizerWnd->SetSizeHints(this); sizerWnd->Fit(this); m_ctlCounties->SetFocus(); btnOk->SetDefault(); Center();}//////////////////////////////////////////////////////////////////////////////////// \brief Ok clicked - save the selection to the vector m_strSelCounties/////////////////////////////////////////////////////////////////////////////////void CountyDialog::OnOk(wxCommandEvent& event){ long item = -1; m_strSelCounties.clear(); item = m_ctlCounties->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); while (item >= 0) { m_strSelCounties.push_back((wxString) m_ctlCounties->GetItemText(item)); item = m_ctlCounties->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); } EndModal(wxID_OK);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -