#include "frmContactEditorRoles.h" #include #include "../enums.h" #include "../common/textprocessing.h" frmContactEditorRoles::frmContactEditorRoles( wxWindow* parent ) : frmContactEditorRolesADT( parent ) { EditorMode = FALSE; sliPriority->Disable(); } void frmContactEditorRoles::EnablePriority( wxCommandEvent& event ) { if (chkUsePref->IsChecked()){ sliPriority->Enable(); } else { sliPriority->Disable(); } } void frmContactEditorRoles::ProcessAction( wxCommandEvent& event ) { // 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 website priority. if (chkUsePref->IsChecked()){ RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->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 (chkUsePref->IsChecked()){ RolesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->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 (chkUsePref->IsChecked()){ RolesListPrefPtr->insert(std::make_pair(RolesListIndex, sliPriority->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 (chkUsePref->IsChecked()){ RolesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue())); } else { RolesListCtrlPtr->SetItem(longSelected, 1, wxT("")); } this->Close(); } } void frmContactEditorRoles::SetEditorMode(bool EditMode, SectionType SectType) { // 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){ sliPriority->SetValue(intiter->second); sliPriority->Enable(); chkUsePref->SetValue(TRUE); } } EditSectionType = SectType; } void frmContactEditorRoles::CloseWindow( wxCommandEvent& event ) { 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 ) { RolesListPtr = RolesList; RolesListLanguagePtr = RolesListLanguage; RolesListAltIDPtr = RolesListAltID; RolesListPIDPtr = RolesListPID; RolesListTypePtr = RolesListType; RolesListTokensPtr = RolesListTokens; RolesListPrefPtr = RolesListPref; RolesListCtrlPtr = RolesListCtrl; RolesListIndex = RolesIndex; }