// frmContactEditorGeoposition.cpp - frmContactEditorGeoposition form. // // (c) 2012-2015 Xestia Software Development. // // This file is part of Xestia Address Book. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book 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 Xestia Address Book. If not, see #include "frmContactEditorGeoposition.h" #include #include "../common/textprocessing.h" frmContactEditorGeoposition::frmContactEditorGeoposition( wxWindow* parent ) : frmContactEditorGeopositionADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); } void frmContactEditorGeoposition::SetEditorMode(bool EditMode, SectionType SectType) { // Setup the editor mode. // Set the editor mode for adding or editing a timezone. if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Geoposition")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Geoposition")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. striter = GeopositionListPtr->find(GeopositionListIndex); if (striter->first == GeopositionListIndex){ strValue = striter->second; } txtGeoposition->SetValue(strValue); // Setup the Slider. intiter = GeopositionListPrefPtr->find(GeopositionListIndex); if (intiter->first == GeopositionListIndex && intiter->second > 0 && intiter != GeopositionListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorGeoposition::ProcessAction( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the language to the list. wxString strValue; strValue = txtGeoposition->GetValue(); // Add language. GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, strValue)); // Add Email type. if (EditSectionType == CE_GENERAL){ GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { GeopositionListTypePtr->insert(std::make_pair(GeopositionListIndex, wxT("work"))); } // Add Language priority. if (priorityCtrl->IsPriorityChecked()){ GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue())); } else { GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0)); } // Add the data to the form. wxListItem coldata; coldata.SetId(GeopositionListIndex); coldata.SetData(GeopositionListIndex); coldata.SetText(txtGeoposition->GetValue()); ListCtrlIndex = GeopositionListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ GeopositionListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE){ // Edit the language. wxString strAddress; wxString strValue; long longSelected = -1; GeopositionListPtr->erase(GeopositionListIndex); GeopositionListPtr->insert(std::make_pair(GeopositionListIndex, txtGeoposition->GetValue())); GeopositionListPrefPtr->erase(GeopositionListIndex); if (priorityCtrl->IsPriorityChecked()){ GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, priorityCtrl->GetValue())); } else { GeopositionListPrefPtr->insert(std::make_pair(GeopositionListIndex, 0)); } longSelected = GeopositionListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } GeopositionListCtrlPtr->SetItem(longSelected, 0, txtGeoposition->GetValue()); if (priorityCtrl->IsPriorityChecked()){ GeopositionListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { GeopositionListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorGeoposition::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorGeoposition::SetupPointers(std::map *GeopositionList, std::map *GeopositionListAltID, std::map *GeopositionListPID, std::map *GeopositionListType, std::map *GeopositionListDataType, std::map *GeopositionListTokens, std::map *GeopositionListMediatype, std::map *GeopositionListPref, wxListCtrl *GeopositionListCtrl, int GeopositionIndex ) { // Setup the pointers so that the data can be processed without // duplication. GeopositionListPtr = GeopositionList; GeopositionListAltIDPtr = GeopositionListAltID; GeopositionListPIDPtr = GeopositionListPID; GeopositionListTypePtr = GeopositionListType; GeopositionListDataTypePtr = GeopositionListDataType; GeopositionListTokensPtr = GeopositionListTokens; GeopositionListPrefPtr = GeopositionListPref; GeopositionListCtrlPtr = GeopositionListCtrl; GeopositionListIndex = GeopositionIndex; }