// frmContactEditorCategory.cpp - frmContactEditorCategory 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 "frmContactEditorCategory.h" #include #include "../common/textprocessing.h" frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent ) : frmContactEditorCategoryADT( parent ) { // Setup the window. EditorMode = FALSE; priorityCtrl = new XABPriorityCtrl(tabGeneral); szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5); cmbType->Append(wxT("")); cmbType->Append(_("Home")); cmbType->Append(_("Work")); } void frmContactEditorCategory::ProcessAction( wxCommandEvent& event ) { // Process action. long ListCtrlIndex; if (EditorMode == FALSE){ wxString strValue; // Setup Organisation Name. CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue())); strValue.Clear(); strValue = cmbType->GetString(cmbType->GetSelection()); // Setup Category Type. if (strValue == _("Home")) { CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home"))); } else if (strValue == _("Work")) { CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work"))); } else { CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT(""))); } // Setup Category Priority. if (priorityCtrl->IsPriorityChecked()){ CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue())); } else { CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0)); } // Add to form. wxListItem coldata; coldata.SetId(CategoryListIndex); coldata.SetData(CategoryListIndex); coldata.SetText(txtCategory->GetValue()); ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata); if (priorityCtrl->IsPriorityChecked()){ CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } this->Close(); } else if (EditorMode == TRUE) { long longSelected = -1; wxString strValue; // Update Category Name. CategoryListPtr->erase(CategoryListIndex); CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue())); // Update Category Type. CategoryListTypePtr->erase(CategoryListIndex); strValue = cmbType->GetString(cmbType->GetSelection()); if (strValue == _("Home")) { CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home"))); } else if (strValue == _("Work")) { CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work"))); } // Update Category Priority. CategoryListPrefPtr->erase(CategoryListIndex); if (priorityCtrl->IsPriorityChecked()){ CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue())); } else { CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0)); } // Update form. longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue()); if (priorityCtrl->IsPriorityChecked()){ CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue())); } else { CategoryListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorCategory::SetEditorMode(bool EditMode) { // 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 Category")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Category")); // Load the data into the form. std::map::iterator intiter; std::map::iterator striter; wxString strValue; // Get the organisation name. striter = CategoryListPtr->find(CategoryListIndex); if (striter->first == CategoryListIndex){ strValue = striter->second; } txtCategory->SetValue(strValue); strValue.Clear(); // Get the type. striter = CategoryListTypePtr->find(CategoryListIndex); if (striter->first == CategoryListIndex && striter != CategoryListTypePtr->end()){ strValue = striter->second; } if (strValue == wxT("home")){ cmbType->SetSelection(1); } else if (strValue == wxT("work")){ cmbType->SetSelection(2); } else { cmbType->SetSelection(0); } // Get the organisation priority. intiter = CategoryListPrefPtr->find(CategoryListIndex); if (intiter->first == CategoryListIndex && intiter->second > 0 && intiter != CategoryListPrefPtr->end()){ priorityCtrl->SetValue(intiter->second); priorityCtrl->EnablePriority(true); } } } void frmContactEditorCategory::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); } void frmContactEditorCategory::SetupPointers(std::map *CategoryList, std::map *CategoryListAltID, std::map *CategoryListPID, std::map *CategoryListType, std::map *CategoryListTokens, std::map *CategoryListPref, wxListCtrl *CategoryListCtrl, int CategoryIndex ) { // Setup the pointers. CategoryListPtr = CategoryList; CategoryListAltIDPtr = CategoryListAltID; CategoryListPIDPtr = CategoryListPID; CategoryListTypePtr = CategoryListType; CategoryListTokensPtr = CategoryListTokens; CategoryListPrefPtr = CategoryListPref; CategoryListCtrlPtr = CategoryListCtrl; CategoryListIndex = CategoryIndex; }