📄 app.cpp
字号:
/* * Roadnav * App.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////// Application code.////// Contains the entry point for the application.///////////////////////////////////////////////////////////////////////////////// #ifdef HAVE_CONFIG_H# include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#endif#include <wx/wx.h>#include <wx/image.h>#include <wx/config.h>#include <wx/fs_zip.h>#include <wx/fs_inet.h>#include <wx/socket.h>#include <wx/stdpaths.h>#include "App.h"#include "Frame.h"#include "libroadnav/Map.h"#include "TTS.h"#include "libroadnav/URLs.h"#include "libroadnav/MapSupport.h"#include "Support.h"#include "libroadnav/DownloadFiles.h"#include "libroadnav/Debug.h"#include "splash.xpm"wxConfigBase * g_pConfig = NULL;IMPLEMENT_APP(MapApp)#if !LIBROADNAV_CHECK_VERSION(0, 17)#error Requires at least version 0.17 of LibRoadnav#endif#if !wxCHECK_VERSION(2, 6, 2)#error Requires at least version 2.6.2 of wxWidgets#endif///////////////////////////////////////////////////////////////////////////////// /// \brief Show the splash screen/////////////////////////////////////////////////////////////////////////////////void MapApp::ShowSplash(){ wxBitmap bmpSplash(splash_xpm); m_wndSplash = new wxSplashScreen( bmpSplash, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, NULL, -1, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR ); m_wndSplash->SetTitle(wxT("Roadnav")); wxYield();}//////////////////////////////////////////////////////////////////////////////////// \brief Hide the splash screen/////////////////////////////////////////////////////////////////////////////////void MapApp::HideSplash(){ delete m_wndSplash;}//////////////////////////////////////////////////////////////////////////////////// \brief Initialization code/////////////////////////////////////////////////////////////////////////////////bool MapApp::OnInit(){#if defined(__WINDOWS__) if (!IsDebuggerPresent()) { // this improves Windows memory performance quite a bit ULONG ulEnableLFH = 2; //try 1 else BOOL bSuccess = HeapSetInformation((PVOID) _get_heap_handle(), HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH)); }#endif SetVendorName(wxT("")); SetAppName(wxT("roadnav")); g_pConfig = wxConfigBase::Get(); g_pConfig->SetRecordDefaults(); g_pConfig->SetExpandEnvVars(false); wxSocketBase::Initialize(); if (!wxApp::OnInit()) return false; //////////////////////////////////////////////////////////////// // For some reason, if a wxScreenDC is not instantiated, it's // not possible to focus the Roadnav window under OSX. //////////////////////////////////////////////////////////////// wxScreenDC dcScreen; //////////////////////////////////////////////////////////////// // Initialize stuff //////////////////////////////////////////////////////////////// wxInitAllImageHandlers(); wxFileSystem::AddHandler(new wxZipFSHandler); wxFileSystem::AddHandler(new wxInternetFSHandler);#ifdef LIBROADNAV_DEBUG if (g_pConfig->Read(wxT("GenerateDebugLog"), (long) 0)) LibRoadnavDebugEnable();#endif //////////////////////////////////////////////////////////////// // Splash screen on, if debug mode not used ////////////////////////////////////////////////////////////////#ifndef _DEBUG ShowSplash();#endif //////////////////////////////////////////////////////////////// // Set up configuration object //////////////////////////////////////////////////////////////// SetURLConfig(g_pConfig); //////////////////////////////////////////////////////////////// // Common data path //////////////////////////////////////////////////////////////// SetCommonDataPath(RoadnavCommonDirectory()); //////////////////////////////////////////////////////////////// // Local data path //////////////////////////////////////////////////////////////// wxFileName fnLocal; wxStandardPathsBase & p = wxStandardPaths::Get(); fnLocal.AssignDir(p.GetUserDataDir() + wxT("data")); if (!fnLocal.DirExists()) fnLocal.Mkdir(0755); fnLocal.AppendDir(wxT("compiled_maps")); SetLocalDataPath(fnLocal.GetFullPath()); ////////////////////////////////////////////////////////////////////////////// // Download cache directory ////////////////////////////////////////////////////////////////////////////// wxFileName fnCache; fnCache.AssignDir(p.GetUserDataDir() + wxT("data")); fnCache.AppendDir(wxT("http_cache")); SetDownloadCacheDirectory(fnCache.GetFullPath()); ////////////////////////////////////////////////////////////////////////////// // Proxy settings ////////////////////////////////////////////////////////////////////////////// long lPort = 0; SetProxyHost(g_pConfig->Read(wxT("ProxyHost"), wxT(""))); g_pConfig->Read(wxT("ProxyPort"), &lPort); SetProxyPort(lPort); //////////////////////////////////////////////////////////////// // Eliminate splash screen ////////////////////////////////////////////////////////////////#ifndef _DEBUG HideSplash();#endif //////////////////////////////////////////////////////////////// // Bring up the main window //////////////////////////////////////////////////////////////// MapFrame * pfMain = new MapFrame(wxT("Roadnav")); pfMain->Show(TRUE); SetTopWindow(pfMain); return TRUE; }void MapApp::OnInitCmdLine(wxCmdLineParser & parser){ wxString strLogo; wxApp::OnInitCmdLine(parser); strLogo = wxT("Roadnav ") wxT(VERSION) wxT("\n"); strLogo += wxT("\nCopyright (c) 2004 - 2007 Richard L. Lynch <rllynch@users.sourceforge.net>\n"); strLogo += wxT("\n"); strLogo += wxT("This program is free software; you can redistribute it and/or\n"); strLogo += wxT("modify it under the terms of version 2 of the GNU General Public License\n"); strLogo += wxT("as published by the Free Software Foundation.\n"); strLogo += wxT("\n"); strLogo += wxT("This program is distributed in the hope that it will be useful,\n"); strLogo += wxT("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); strLogo += wxT("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); strLogo += wxT("GNU General Public License for more details.\n"); strLogo += wxT("\n"); strLogo += wxT("You should have received a copy of the GNU General Public License\n"); strLogo += wxT("along with this program (COPYING in the application folder);\n"); strLogo += wxT("if not, write to the Free Software Foundation, Inc.,\n"); strLogo += wxT("51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"); parser.SetLogo(strLogo); #ifdef LIBROADNAV_DEBUG parser.AddSwitch(wxT("d"), wxT("debug"), wxT("Enable debugging"));#endif#ifdef USE_SCRIPTING parser.AddOption(wxT("c"), wxT("command"), wxT("Send scripting command to TCP server"));#endif}//////////////////////////////////////////////////////////////////////////////////// \brief Called to parse command line arguments./////////////////////////////////////////////////////////////////////////////////bool MapApp::OnCmdLineParsed(wxCmdLineParser & parser){ bool bContinue = true; wxString strArg; if (!wxApp::OnCmdLineParsed(parser)) bContinue = false; #ifdef LIBROADNAV_DEBUG if (parser.Found(wxT("d"))) LibRoadnavDebugEnable();#endif#ifdef USE_SCRIPTING if (parser.Found(wxT("c"), &strArg)) { int iServerPort = -1; if (g_pConfig->Read(wxT("ScriptingTCPServerEnabled"), (long) 0)) iServerPort = g_pConfig->Read(wxT("ScriptingTCPServerPortNumber"), DEFAULT_SCRIPTING_TCP_PORT_NUMBER); if (iServerPort >= 0) { wxSocketClient sockRoadnav; wxIPV4address addrRoadnav; addrRoadnav.Hostname(wxT("127.0.0.1")); addrRoadnav.Service(iServerPort); sockRoadnav.Connect(addrRoadnav, true); if (sockRoadnav.IsConnected()) { char * pszMsg; pszMsg = new char [strArg.Length() + 3]; strcpy(pszMsg, strArg.mb_str(*wxConvCurrent)); strcat(pszMsg, "\r\n"); sockRoadnav.Write(pszMsg, strlen(pszMsg)); sockRoadnav.Close(); delete pszMsg; } else { // Roadnav not running - silently ignore } } else { wxMessageBox( wxT("The scripting TCP server must be abled to use the -c command line option."), wxT("Error"), wxOK | wxICON_ERROR); } bContinue = false; }#endif return bContinue;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -