// frmContactEditorRoles.cpp - frmContactEditorRoles 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 "frmContactEditorRoles.h" #include #include "../enums.h" #include "../common/textprocessing.h" frmContactEditorRoles::frmContactEditorRoles( wxWindow* parent ) : frmContactEditorRolesADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); } void frmContactEditorRoles::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. RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue())); // Get the type of website. if (EditSectionType == CE_GENERAL){ RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { RolesListTypePtr->insert(std::make_pair(RolesListIndex, wxT("work"))); } // Add the roles priority. if (priorityCtrl->IsPriorityChecked()){ RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue())); } else { RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0)); } // Add to the form. wxListItem coldata; coldata.SetId(RolesListIndex); coldata.SetData(RolesListIndex); coldata.SetText(txtRole->GetValue()); ListCtrlIndex = RolesListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else { // Update the title. long longSelected = -1; wxString strValue; RolesListPtr->erase(RolesListIndex); RolesListPtr->insert(std::make_pair(RolesListIndex, txtRole->GetValue())); // Update the slider priority. RolesListPrefPtr->erase(RolesListIndex); if (priorityCtrl->IsPriorityChecked()){ RolesListPrefPtr->insert(std::make_pair(RolesListIndex, priorityCtrl->GetValue())); } else { RolesListPrefPtr->insert(std::make_pair(RolesListIndex, 0)); } // Update the form. longSelected = RolesListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } RolesListCtrlPtr->SetItem(longSelected, 0, txtRole->GetValue()); if (priorityCtrl->IsPriorityChecked()){ RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { RolesListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorRoles::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 = RolesListPtr->find(RolesListIndex); if (striter->first == RolesListIndex){ strValue = striter->second; } txtRole->SetValue(strValue); strValue.Clear(); // Get the website priority. intiter = RolesListPrefPtr->find(RolesListIndex); if (intiter->first == RolesListIndex && intiter->second > 0 && intiter != RolesListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorRoles::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorRoles::SetupPointers(std::map *RolesList, std::map *RolesListLanguage, std::map *RolesListAltID, std::map *RolesListPID, std::map *RolesListType, std::map *RolesListTokens, std::map *RolesListPref, wxListCtrl *RolesListCtrl, int RolesIndex ) { // Setup the pointers. RolesListPtr = RolesList; RolesListLanguagePtr = RolesListLanguage; RolesListAltIDPtr = RolesListAltID; RolesListPIDPtr = RolesListPID; RolesListTypePtr = RolesListType; RolesListTokensPtr = RolesListTokens; RolesListPrefPtr = RolesListPref; RolesListCtrlPtr = RolesListCtrl; RolesListIndex = RolesIndex; }