// frmContactEditorLanguages.cpp - frmContactEditorLanguages 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 "frmContactEditorLanguages.h" #include "../common/textprocessing.h" #include frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent ) : frmContactEditorLanguagesADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); } void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType) { // Set the editor mode for adding or editing an email address. if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Language")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Language")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. striter = LanguageListPtr->find(LanguageListIndex); if (striter->first == LanguageListIndex){ strValue = striter->second; } txtLanguage->SetValue(strValue); // Setup the Slider. intiter = LanguageListPrefPtr->find(LanguageListIndex); if (intiter->first == LanguageListIndex && intiter->second > 0 && intiter != LanguageListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event ) { // Process the action. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the language to the list. wxString strValue; // Add language. LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue())); // Add Email type. if (EditSectionType == CE_GENERAL){ LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work"))); } // Add Language priority. if (priorityCtrl->IsPriorityChecked()){ LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue())); } else { LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0)); } // Add the data to the form. wxListItem coldata; coldata.SetId(LanguageListIndex); coldata.SetData(LanguageListIndex); coldata.SetText(txtLanguage->GetValue()); ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ LanguageListCtrlPtr->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; LanguageListPtr->erase(LanguageListIndex); LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue())); LanguageListPrefPtr->erase(LanguageListIndex); if (priorityCtrl->IsPriorityChecked()){ LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue())); } else { LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0)); } longSelected = LanguageListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue()); if (priorityCtrl->IsPriorityChecked()){ LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { LanguageListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event ) { // Close the window. this->Close(); } void frmContactEditorLanguages::SetupPointers(std::map *LanguageList, std::map *LanguageListAltID, std::map *LanguageListPID, std::map *LanguageListType, std::map *LanguageListTokens, std::map *LanguageListPref, wxListCtrl *LanguageListCtrl, int LanguageIndex ) { // Setup the pointers so that the data can be processed without // duplication. LanguageListPtr = LanguageList; LanguageListAltIDPtr = LanguageListAltID; LanguageListPIDPtr = LanguageListPID; LanguageListTypePtr = LanguageListType; LanguageListTokensPtr = LanguageListTokens; LanguageListPrefPtr = LanguageListPref; LanguageListCtrlPtr = LanguageListCtrl; LanguageListIndex = LanguageIndex; }