📄 locationdialog.cpp
字号:
/// \brief Cancel pressed/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnCancel(wxCommandEvent& event){ m_Timer->Stop(); EndModal(wxID_CANCEL);}//////////////////////////////////////////////////////////////////////////////////// \brief Update the member variables with the contents of the controls/// for this dialog, and the notebook pages./////////////////////////////////////////////////////////////////////////////////void LocationDialog::UpdateData(){ TransferDataFromWindow(); m_pwndAddress->TransferDataFromWindow(); m_pwndCoordinates->TransferDataFromWindow(); m_iActivePage = m_pctlNotebook->GetSelection();}//////////////////////////////////////////////////////////////////////////////////// \brief Add current address as a marker./////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnAdd(wxCommandEvent& event){ if (!m_pctlMap) return; wxString strErrorMsg; Address sAddr; int iSel; UpdateData(); if (!MayClose()) return; sAddr = GetAddress(&strErrorMsg); if (!sAddr.m_bValid) { ::wxMessageBox(strErrorMsg, wxT("Error"), wxOK, this); return; } if (m_strName == wxT("")) { ::wxMessageBox(wxT("Waypoint name required"), wxT("Error"), wxOK, this); return; } MapMarker cMarker(m_strName, &sAddr, -1, m_bShowCalloutBox, m_bShowSmallLabel, true, m_strIconFilename, m_bScaleIcon, m_bVisible); m_pctlMap->SetMarker(cMarker); PopulateListBox(); iSel = m_ctlOldAddresses->FindString(cMarker.m_strName + wxT(" (") + cMarker.m_cAddress.FormatAddress(false, true) + wxT(")")); wxASSERT(iSel >= 0); m_ctlOldAddresses->SetSelection(iSel);}//////////////////////////////////////////////////////////////////////////////////// \brief Update selected marker with current address/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnUpdate(wxCommandEvent& event){ UpdateData(); if (!MayClose()) return; OnDelete(event); OnAdd(event);}//////////////////////////////////////////////////////////////////////////////////// \brief Delete selected marker/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnDelete(wxCommandEvent& event){ unsigned int iSel; if (!m_pctlMap) return; iSel = m_ctlOldAddresses->GetSelection(); if (iSel < 0) return; MapMarker & cMarker = m_pctlMap->GetMarker(iSel); m_pctlMap->ClearMarker(cMarker.m_strName); PopulateListBox(); if (m_ctlOldAddresses->GetCount() <= iSel) iSel--; if (iSel >= 0) m_ctlOldAddresses->SetSelection(iSel);}//////////////////////////////////////////////////////////////////////////////////// \brief Export current address to scripting file/////////////////////////////////////////////////////////////////////////////////#ifdef USE_SCRIPTINGvoid LocationDialog::OnExport(wxCommandEvent& event){ wxString strErrorMsg; Address sAddr; UpdateData(); sAddr = GetAddress(&strErrorMsg); if (!sAddr.m_bValid) { ::wxMessageBox(strErrorMsg, wxT("Error"), wxOK, this); return; } if (m_strName == wxT("")) { ::wxMessageBox(wxT("Waypoint name required"), wxT("Error"), wxOK, this); return; } MapMarker cMarker(m_strName, &sAddr, -1, m_bShowCalloutBox, m_bShowSmallLabel, true, m_strIconFilename, 1, m_bVisible); if (GetScriptExportFilename() != wxT("")) { if (!Scripting::WriteWaypointToFile(GetScriptExportFilename(), GetScriptAppendMode(), cMarker)) { ::wxMessageBox(wxT("Waypoint exported successfully"), wxT("Information"), wxICON_INFORMATION | wxOK, this); } else { ::wxMessageBox(wxT("Error exporting marker (bad filename?)"), wxT("Error"), wxICON_ERROR | wxOK, this); } } else { ::wxMessageBox(wxT("You must configure the export filename in Preferences before using the export function."), wxT("Error"), wxICON_ERROR | wxOK, this); }}#endif//////////////////////////////////////////////////////////////////////////////////// \brief Export all waypoints to scripting file/////////////////////////////////////////////////////////////////////////////////#ifdef USE_SCRIPTINGvoid LocationDialog::OnExportAll(wxCommandEvent& event){ wxString strErrorMsg; if (GetScriptExportFilename() != wxT("")) { int iMarker; int iErrors; iErrors = 0; for (iMarker = 0; iMarker < m_pctlMap->GetMarkerCount(); iMarker++) { if (Scripting::WriteWaypointToFile(GetScriptExportFilename(), GetScriptAppendMode(), m_pctlMap->GetMarker(iMarker))) { // error exporting iErrors++; } } if (!iErrors) { ::wxMessageBox(wxString::Format(wxT("%d Waypoints exported successfully"), m_pctlMap->GetMarkerCount()), wxT("Information"), wxICON_INFORMATION | wxOK, this); } else { ::wxMessageBox(wxT("Error exporting markers (bad filename?)"), wxT("Error"), wxICON_ERROR | wxOK, this); } } else { ::wxMessageBox(wxT("You must configure the export filename in Preferences before using the export function."), wxT("Error"), wxICON_ERROR | wxOK, this); }}#endif//////////////////////////////////////////////////////////////////////////////////// \brief Browse button pressed. Lets a bitmap be used to indicate a marker's/// location./////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnIconBrowse(wxCommandEvent& event){ wxFileDialog dlg(this, wxT("Select icon..."), wxT(""), wxT(""), wxT("Images|*.bmp;*.png;*.jpg;*.jpeg;*.gif;*.pcx;*.pnm;*.tif;*.tiff;*.xpm;*.ico"),#if wxCHECK_VERSION(2, 8, 0) wxFD_OPEN#else wxOPEN#endif ); if (dlg.ShowModal() == wxID_OK) { TransferDataFromWindow(); m_strIconFilename = dlg.GetPath(); TransferDataToWindow(); }}//////////////////////////////////////////////////////////////////////////////////// \brief Selection changed in old address listing.////// This function populates the edit controls with the address selected in the/// old address listing./////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnOldAddress(wxCommandEvent & event){ int iSel; iSel = m_ctlOldAddresses->GetSelection(); if (iSel < 0) return; MapMarker & cMarker = m_pctlMap->GetMarker(iSel); m_strName = cMarker.m_strName; m_strIconFilename = cMarker.m_strIcon; m_bShowCalloutBox = cMarker.m_bCalloutBox; m_bShowSmallLabel = cMarker.m_bSmallLabel; m_bVisible = cMarker.m_bVisible; m_bScaleIcon = cMarker.m_bScaleIcon; TransferDataToWindow(); m_pwndAddress->SetAddress(cMarker.m_cAddress); m_pwndCoordinates->SetAddress(cMarker.m_cAddress);}//////////////////////////////////////////////////////////////////////////////////// \brief List box entry double clicked - center map on that marker/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnOldAddressDoubleClick(wxCommandEvent & event){ int iSel; iSel = m_ctlOldAddresses->GetSelection(); if (iSel < 0) return; OnOldAddress(event); MapMarker & cMarker = m_pctlMap->GetMarker(iSel); m_pctlMap->SetCenterCoordinates(cMarker.m_cAddress.m_ptCoordinates);}//////////////////////////////////////////////////////////////////////////////////// \brief Obtain the entered address./////////////////////////////////////////////////////////////////////////////////Address LocationDialog::GetAddress(wxString * pstrErrorMsg){ Address cBlank; switch (m_iActivePage) { case 0: return m_pwndAddress->GetAddress(pstrErrorMsg, m_bRoadsOnly); case 1: return m_pwndCoordinates->GetAddress(pstrErrorMsg, m_bRoadsOnly); } wxASSERT(0); *pstrErrorMsg = wxT("Internal error"); return cBlank;}//////////////////////////////////////////////////////////////////////////////////// \brief Keyboard button pressed - activate onscreen keyboard/// (KeyboardDialog)/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnKeyboard(wxCommandEvent & event){ if (!m_pwndFocused) return; switch (m_pctlNotebook->GetSelection()) { case 0: m_pwndAddress->UpdateAutoCompletionObjects(m_bRoadsOnly); break; case 1: //m_pwndCoordinates->UpdateAutoCompletionObjects(m_bRoadsOnly); break; } KeyboardDialog dlg( this, wxT("Keyboard"), m_pwndFocused, m_pctlMap->GetDetailSettings()->GetMiscColor(MiscColorBackground), m_pctlMap->GetDetailSettings()->GetMiscColor(MiscColorForeground), m_pcAutoComplete); m_Timer->Stop(); dlg.ShowModal(); m_Timer->Start(100); m_pwndFocused->SetFocus();}//////////////////////////////////////////////////////////////////////////////////// \brief 100ms timer - tracks which wxTextCtrl has focus in m_pwndFocused/////////////////////////////////////////////////////////////////////////////////void LocationDialog::OnTimer(wxTimerEvent& event){ wxWindow * pwndFocused; pwndFocused = wxWindow::FindFocus(); if (!pwndFocused) return; if (pwndFocused->IsKindOf(CLASSINFO(wxTextCtrl))) m_pwndFocused = wxDynamicCast(pwndFocused, wxTextCtrl);; m_pcAutoComplete = NULL; switch (m_pctlNotebook->GetSelection()) { case 0: m_pcAutoComplete = m_pwndAddress->m_mapWndToAutoComplete[m_pwndFocused]; break; case 1: //m_pcAutoComplete = m_pwndCoordinates->AutoCompletionObject[m_pwndFocused]; break; }}//////////////////////////////////////////////////////////////////////////////////// \brief Returns if the dialog can close. Generally returns false if an/// invalid address has been put in./////////////////////////////////////////////////////////////////////////////////bool LocationDialog::MayClose(){ switch (m_iActivePage) { case 0: return m_pwndAddress->MayClose(m_bRoadsOnly); case 1: return m_pwndCoordinates->MayClose(m_bRoadsOnly); } wxASSERT(0); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -