// frmContactEditorOrganisation.cpp - frmContactEditorOrganisation 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 "frmContactEditorOrganisations.h" #include #include "../common/textprocessing.h" frmContactEditorOrganisations::frmContactEditorOrganisations( wxWindow* parent ) : frmContactEditorOrganisationsADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); szrGeneral->Layout(); } void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event ) { // Update the predefined SortAs listings. // Clear out the options for the combo box. cmbSortAs->Clear(); cmbSortAs->Append(txtOrganisation->GetValue()); // See if there are more than one word, if not leave drop down // with the default organisation name. wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" ")); wxString strArrange; wxString strFirst; wxString strArrFinal; if (tknOrg.CountTokens() > 1){ strFirst = tknOrg.GetNextToken(); while (tknOrg.HasMoreTokens()){ strArrange.Append(tknOrg.GetNextToken()); if (tknOrg.CountTokens() != 0){ strArrange.Append(wxT(" ")); } } strArrFinal.Append(strArrange); strArrFinal.Append(wxT(", ")); strArrFinal.Append(strFirst); cmbSortAs->Append(strArrFinal); } } void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ wxString strValue; // Setup Organisation Name. OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue())); // Setup Organisation Type. if (EditSectionType == CE_GENERAL){ OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work"))); } // Setup Organisation SortAs. strValue.Clear(); OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue())); // Setup Organisation Priority. if (priorityCtrl->IsPriorityChecked()){ OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue())); } else { OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0)); } // Add to form. wxListItem coldata; coldata.SetId(OrganisationListIndex); coldata.SetData(OrganisationListIndex); coldata.SetText(txtOrganisation->GetValue()); ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE) { long longSelected = -1; wxString strValue; // Update Organisation Name. OrganisationListPtr->erase(OrganisationListIndex); OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue())); // Update Organisation SortAs. strValue.Clear(); OrganisationListSortAsPtr->erase(OrganisationListIndex); OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue())); // Update Organisation Priority. OrganisationListPrefPtr->erase(OrganisationListIndex); if (priorityCtrl->IsPriorityChecked()){ OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue())); } else { OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0)); } // Update form. longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue()); if (priorityCtrl->IsPriorityChecked()){ OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorOrganisations::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 Organisation")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Organisation")); // Load the data into the form. std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Get the organisation name. striter = OrganisationListPtr->find(OrganisationListIndex); if (striter->first == OrganisationListIndex){ strValue = striter->second; } txtOrganisation->SetValue(strValue); strValue.Clear(); // Get the organisation sort as. striter = OrganisationListSortAsPtr->find(OrganisationListIndex); if (striter->first == OrganisationListIndex && striter != OrganisationListSortAsPtr->end()){ strValue = striter->second; } cmbSortAs->SetValue(strValue); // Get the organisation priority. intiter = OrganisationListPrefPtr->find(OrganisationListIndex); if (intiter->first == OrganisationListIndex && intiter->second > 0 && intiter != OrganisationListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } EditSectionType = SectType; } void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event ) { // Close the window. this->Close(); } void frmContactEditorOrganisations::SetupPointers(std::map *OrganisationList, std::map *OrganisationListLanguage, std::map *OrganisationListSortAs, std::map *OrganisationListAltID, std::map *OrganisationListPID, std::map *OrganisationListType, std::map *OrganisationListTokens, std::map *OrganisationListPref, wxListCtrl *OrganisationListCtrl, int OrganisationIndex ) { // Setup the pointers. OrganisationListPtr = OrganisationList; OrganisationListLanguagePtr = OrganisationListLanguage; OrganisationListSortAsPtr = OrganisationListSortAs; OrganisationListAltIDPtr = OrganisationListAltID; OrganisationListPIDPtr = OrganisationListPID; OrganisationListTypePtr = OrganisationListType; OrganisationListTokensPtr = OrganisationListTokens; OrganisationListPrefPtr = OrganisationListPref; OrganisationListCtrlPtr = OrganisationListCtrl; OrganisationListIndex = OrganisationIndex; }