// frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h" #include #include "../enums.h" #include "../common/textprocessing.h" frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent ) : frmContactEditorTitlesADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); } void frmContactEditorTitles::ProcessAction( wxCommandEvent& event ) { // Process action. // Set if the editor is adding or editing an address. // FALSE = Add // TRUE = Edit long ListCtrlIndex; if (EditorMode == FALSE){ wxString strValue; // Get the website address. TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue())); // Get the type of website. if (EditSectionType == CE_GENERAL){ TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work"))); } // Add the website priority. if (priorityCtrl->IsPriorityChecked()){ TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue())); } else { TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0)); } // Add to the form. wxListItem coldata; coldata.SetId(TitlesListIndex); coldata.SetData(TitlesListIndex); coldata.SetText(txtTitle->GetValue()); ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else { // Update the title. long longSelected = -1; wxString strValue; TitlesListPtr->erase(TitlesListIndex); TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue())); // Update the slider priority. TitlesListPrefPtr->erase(TitlesListIndex); if (priorityCtrl->IsPriorityChecked()){ TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue())); } else { TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0)); } // Update the form. longSelected = TitlesListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue()); if (priorityCtrl->IsPriorityChecked()){ TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { TitlesListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType) { // Set the editor mode. // Set if the editor is adding or editing an address. // FALSE = Add // TRUE = Edit if (EditMode == FALSE){ EditorMode = FALSE; btnAction->SetLabel(_("Add")); this->SetTitle(_("Add Title")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Title")); std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Load the data into the form. Get the website. striter = TitlesListPtr->find(TitlesListIndex); if (striter->first == TitlesListIndex && striter != TitlesListPtr->end()){ strValue = striter->second; } txtTitle->SetValue(strValue); strValue.Clear(); // Get the website priority. intiter = TitlesListPrefPtr->find(TitlesListIndex); if (intiter->first == TitlesListIndex && intiter->second > 0 && intiter != TitlesListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorTitles::CloseWindow( wxCommandEvent& event ) { // Close the window. this->Close(); } void frmContactEditorTitles::SetupPointers(std::map *TitlesList, std::map *TitlesListLanguage, std::map *TitlesListAltID, std::map *TitlesListPID, std::map *TitlesListType, std::map *TitlesListTokens, std::map *TitlesListPref, wxListCtrl *TitlesListCtrl, int TitlesIndex ) { // Setup the pointers. TitlesListPtr = TitlesList; TitlesListLanguagePtr = TitlesListLanguage; TitlesListAltIDPtr = TitlesListAltID; TitlesListPIDPtr = TitlesListPID; TitlesListTypePtr = TitlesListType; TitlesListTokensPtr = TitlesListTokens; TitlesListPrefPtr = TitlesListPref; TitlesListCtrlPtr = TitlesListCtrl; TitlesListIndex = TitlesIndex; }