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

📄 waypointdialog.cpp

📁 Powerful and Portable GPS application -- support Linux, Windows, Windows CE GPS navigation and Map m
💻 CPP
字号:
/*
 *  Roadnav
 *  WaypointDialog.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 an existing waypoint
///
//////////////////////////////////////////////////////////////////////////////

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#ifdef _MSC_VER
#pragma warning(disable: 4786)
#endif

#include <wx/wx.h>
#include <wx/valgen.h>

#include "WaypointDialog.h"
#include "libroadnav/Map.h"
#include "libroadnav/MapLookup.h"
#include "libroadnav/MapState.h"
#include "App.h"
#include "libroadnav/MapAbbreviations.h"
#include "libroadnav/MapZip.h"
#include "libroadnav/MapRepresentations.h"
#include "libroadnav/MapControlDataImporter_TigerLine.h"
#include "libroadnav/MapSupport.h"
#include "KeyboardDialog.h"
#include "Scripting.h"

#include <vector>

using namespace std;

#define CUSTOM_ENTRY		wxT("[Enter a new address]")
#define FONT_SCALE			1.5

//////////////////////////////////////////////////////////////////////////////
/// button IDs
//////////////////////////////////////////////////////////////////////////////
enum
{
	idOldAddresses,
	idAdvanced
};

//////////////////////////////////////////////////////////////////////////////
/// Event table for WaypointDialog
//////////////////////////////////////////////////////////////////////////////
BEGIN_EVENT_TABLE(WaypointDialog, wxDialog)
	EVT_BUTTON(wxID_OK, WaypointDialog::OnOk)
	EVT_BUTTON(wxID_CANCEL, WaypointDialog::OnCancel)
	EVT_BUTTON(idAdvanced, WaypointDialog::OnAdvanced)
END_EVENT_TABLE()

//////////////////////////////////////////////////////////////////////////////
///
/// \brief WaypointDialog constructor - Creates the various controls in the 
/// dialog box
///
//////////////////////////////////////////////////////////////////////////////
WaypointDialog::WaypointDialog(wxWindow *parent, MapControl * pctlMap, wxFont * pFont, wxString strTitleBar, wxString strTitleText) : wxDialog(parent, -1, wxString(strTitleBar))
{
	wxBoxSizer *sizerWnd = new wxBoxSizer(wxVERTICAL);
	int i;
	bool bUseFullScreen = true;
	
	m_cFont = *pFont;
	m_cFont.SetPointSize((int) (pFont->GetPointSize() * FONT_SCALE));
	
	SetFont(m_cFont);	

	//////////////////////////////////////////////////////////////////////////////
	// Save arguments to member variables
	//////////////////////////////////////////////////////////////////////////////
	m_pctlMap = pctlMap;

	SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));

	//////////////////////////////////////////////////////////////////////////////
	// title text
	//////////////////////////////////////////////////////////////////////////////
	wxStaticText * pctlTitleText;
	
	pctlTitleText = new wxStaticText(	this,
										-1,
										strTitleText);

	pctlTitleText->SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	pctlTitleText->SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));

	sizerWnd->Add(pctlTitleText, 0, wxALL, 10);
	

	//////////////////////////////////////////////////////////////////////////////
	// list of old queries
	//////////////////////////////////////////////////////////////////////////////
	m_ctlOldAddresses = new wxListBox(
						this,
						idOldAddresses,
						wxDefaultPosition,
						wxDefaultSize
					);
	
	m_ctlOldAddresses->SetFont(m_cFont);
	m_ctlOldAddresses->Append(CUSTOM_ENTRY);
	
	m_ctlOldAddresses->SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	m_ctlOldAddresses->SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));
	
	for (i = 0; i < m_pctlMap->GetMarkerCount(); i++)
	{
		MapMarker & cMarker = m_pctlMap->GetMarker(i);

		m_ctlOldAddresses->Append(cMarker.m_strName + wxT(" (") + cMarker.m_cAddress.FormatAddress(false, true) + wxT(")"));
	}
	m_ctlOldAddresses->SetSelection(0);

	sizerWnd->Add(m_ctlOldAddresses, 1, wxGROW | wxALL, 10);

	//////////////////////////////////////////////////////////////////////////////
	// ok and cancel button
	//////////////////////////////////////////////////////////////////////////////
    wxBoxSizer * sizerBottom = new wxBoxSizer(wxHORIZONTAL);
    wxSize szButtons = wxDefaultSize;

   	if (bUseFullScreen)
	{
		int iScreenWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
		
		szButtons.x = iScreenWidth / 4;
		szButtons.y = iScreenWidth / 20;
	}
 

    wxButton * btnOk = new wxButton(this, wxID_OK, wxT("&OK"), wxDefaultPosition, szButtons);
	btnOk->SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	btnOk->SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));
	btnOk->SetDefault();
    sizerBottom->Add(btnOk, 0, wxALL, 20);

    wxButton * btnCancel = new wxButton(this, wxID_CANCEL, wxT("&Cancel"), wxDefaultPosition, szButtons);
	btnCancel->SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	btnCancel->SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));
    sizerBottom->Add(btnCancel, 0, wxALL, 20);

    wxButton * btnAdvanced = new wxButton(this, idAdvanced, wxT("&Advanced"), wxDefaultPosition, szButtons);
	btnAdvanced->SetBackgroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground));
	btnAdvanced->SetForegroundColour(pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground));
    sizerBottom->Add(btnAdvanced, 0, wxALL, 20);

	sizerWnd->Add(sizerBottom, 0, wxALIGN_CENTER, 0);
		

	//////////////////////////////////////////////////////////////////////////////
	// layout stuff
	//////////////////////////////////////////////////////////////////////////////
	
    SetAutoLayout(TRUE);
    SetSizer(sizerWnd);

	if (bUseFullScreen)
	{
		int iScreenWidth = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
		int iScreenHeight = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
		
		if (iScreenWidth > 0 && iScreenHeight > 0)
		{
			int iClientWidth;
			int iClientHeight;
			int iTotalWidth;
			int iTotalHeight;
			int iEdgeWidth;
			int iEdgeHeight;
			
			GetClientSize(&iClientWidth, &iClientHeight);
			GetSize(&iTotalWidth, &iTotalHeight);
			iEdgeWidth = iTotalWidth - iClientWidth;
			iEdgeHeight = iTotalHeight - iClientHeight;
			
			iClientWidth = (int) ((iScreenWidth - iEdgeWidth) * 0.95);
#ifdef __DARWIN__
			iClientHeight = (int) ((iScreenHeight - iEdgeHeight - 150) * 0.9);
#else
			iClientHeight = (int) ((iScreenHeight - iEdgeHeight) * 0.8);
#endif

			SetSize(	(iScreenWidth - (iClientWidth + iEdgeWidth)) / 2,
						(iScreenHeight - (iClientHeight + iEdgeHeight)) / 2,
						iClientWidth + iEdgeWidth, 
						iClientHeight + iEdgeHeight);
		}
	}
	
	Layout();

	//////////////////////////////////////////////////////////////////////////////
	// Position dialog
	//////////////////////////////////////////////////////////////////////////////

	m_ctlOldAddresses->SetFocus();

	if (!bUseFullScreen)
		Center();
}

//////////////////////////////////////////////////////////////////////////////
///
/// \brief WaypointDialog destructor - delete m_Timer
///
//////////////////////////////////////////////////////////////////////////////
WaypointDialog::~WaypointDialog()
{
}

//////////////////////////////////////////////////////////////////////////////
/// 
/// \brief This function initializes the prior addresses box, sets the title, 
/// and shows the dialog modally.
///
//////////////////////////////////////////////////////////////////////////////
int WaypointDialog::ShowModal()
{
	return wxDialog::ShowModal();
}

//////////////////////////////////////////////////////////////////////////////
///
/// \brief Ok pressed - Saves the edit controls to member variables.
///
//////////////////////////////////////////////////////////////////////////////
void WaypointDialog::OnOk(wxCommandEvent& event)
{
	int iSel;

	iSel = m_ctlOldAddresses->GetSelection();

	if (iSel < 0)
		return;
	else if (iSel == 0)
		m_cMarker.m_cAddress.m_bValid = false;
	else
	{
		m_cMarker = m_pctlMap->GetMarker(iSel - 1);
		
		// FIXME: should be a more elegant solution than this for the problem
		// of record IDs from previous map compiles.
		if (m_cMarker.m_cAddress.m_ptCoordinates.IsValid())
			m_cMarker.m_cAddress.m_idRecord = FindCoordinates(m_cMarker.m_cAddress.m_ptCoordinates, AllVisibility()).m_idRecord;
	}
	
	EndModal(wxID_OK);
}

//////////////////////////////////////////////////////////////////////////////
///
/// \brief Cancel pressed
///
//////////////////////////////////////////////////////////////////////////////
void WaypointDialog::OnCancel(wxCommandEvent& event)
{
	EndModal(wxID_CANCEL);
}

//////////////////////////////////////////////////////////////////////////////
///
/// \brief Advanced pressed
///
//////////////////////////////////////////////////////////////////////////////
void WaypointDialog::OnAdvanced(wxCommandEvent& event)
{
	EndModal(idAdvanced);
}

MapMarker WaypointDialog::GetMarker()
{
	return m_cMarker;
}

⌨️ 快捷键说明

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