#include "frmContactEditorAddress.h" #include #include #include "../common/textprocessing.h" frmContactEditorAddress::frmContactEditorAddress( wxWindow* parent ) : frmContactEditorAddressADT( parent ) { EditorMode = FALSE; sliPriority->Disable(); } void frmContactEditorAddress::InitAddressEditor( wxInitDialogEvent& event ) { // Do nothing with this subroutine at this time. } void frmContactEditorAddress::EnablePriority( wxCommandEvent& event ) { if (chkUsePref->IsChecked()){ sliPriority->Enable(); } else { sliPriority->Disable(); } } void frmContactEditorAddress::ProcessData( wxCommandEvent& event ) { // Check what edit mode we are in and go from there. long ListCtrlIndex; if (EditorMode == FALSE){ // Add the address to the list (maps). AddressListPtr->erase(AddressListIndex); AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue())); AddressListTownPtr->erase(AddressListIndex); AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue())); AddressListCountyPtr->erase(AddressListIndex); AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue())); AddressListPostCodePtr->erase(AddressListIndex); AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue())); AddressListCountryPtr->erase(AddressListIndex); AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue())); // Add the label to the list (maps). AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue())); // Add the language to the list (maps). AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue())); // No AltIDs at present. // No PIDs at present. // There are no tokens for a new address to add so this can be // ignored for the time being. // Add the Geopositioning to the list (maps). AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue())); // Add the Timezone to the list (maps). AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue())); if (EditSectionType == CE_GENERAL){ AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT(""))); } else if (EditSectionType == CE_HOME) { AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("home"))); } else if (EditSectionType == CE_WORK) { AddressListTypePtr->insert(std::make_pair(AddressListIndex, wxT("work"))); } //AddressListTypePtr = &AddressListType; // Add the mediatype to the list (maps). AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain"))); //AddressListMediatypePtr = &AddressListMediatype; //AddressListPrefPtr = &AddressListPref; if (chkUsePref->IsChecked()){ AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue())); } else { AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0)); } // Add to the form. wxListItem coldata; coldata.SetId(AddressListIndex); coldata.SetData(AddressListIndex); coldata.SetText(txtAddress->GetValue()); ListCtrlIndex = AddressListCtrlPtr->InsertItem(coldata); AddressListCtrlPtr->SetItem(ListCtrlIndex, 1, txtTownCity->GetValue()); AddressListCtrlPtr->SetItem(ListCtrlIndex, 2, txtCounty->GetValue()); AddressListCtrlPtr->SetItem(ListCtrlIndex, 3, txtPostCode->GetValue()); if (chkUsePref->IsChecked()){ AddressListCtrlPtr->SetItem(ListCtrlIndex, 4, wxString::Format(wxT("%i"), sliPriority->GetValue())); } this->Close(); } else if (EditorMode == TRUE){ // Edit the address in the list. wxString strAddress; wxString strValue; long longSelected = -1; /* strAddress.Append(wxT(";;")); strAddress.Append(txtAddress->GetValue()); strAddress.Append(wxT(";")); strAddress.Append(txtTownCity->GetValue()); strAddress.Append(wxT(";")); strAddress.Append(txtCounty->GetValue()); strAddress.Append(wxT(";")); strAddress.Append(txtPostCode->GetValue()); strAddress.Append(wxT(";")); strAddress.Append(txtCountry->GetValue()); */ AddressListPtr->erase(AddressListIndex); AddressListPtr->insert(std::make_pair(AddressListIndex, txtAddress->GetValue())); AddressListTownPtr->erase(AddressListIndex); AddressListTownPtr->insert(std::make_pair(AddressListIndex, txtTownCity->GetValue())); AddressListCountyPtr->erase(AddressListIndex); AddressListCountyPtr->insert(std::make_pair(AddressListIndex, txtCounty->GetValue())); AddressListPostCodePtr->erase(AddressListIndex); AddressListPostCodePtr->insert(std::make_pair(AddressListIndex, txtPostCode->GetValue())); AddressListCountryPtr->erase(AddressListIndex); AddressListCountryPtr->insert(std::make_pair(AddressListIndex, txtCountry->GetValue())); //AddressListLabelPtr = &AddressListLabel; // Add the label to the list (maps). AddressListLabelPtr->erase(AddressListIndex); AddressListLabelPtr->insert(std::make_pair(AddressListIndex, txtLabel->GetValue())); // Add the language to the list (maps). //AddressListLangPtr = &AddressListLang; AddressListLangPtr->erase(AddressListIndex); AddressListLangPtr->insert(std::make_pair(AddressListIndex, cmbLanguage->GetValue())); //AddressListAltIDPtr = &AddressListAltID; // No AltIDs at present. // No PIDs at present. // There are no tokens for a new address to add so this can be // ignored for the time being. // Add the Geopositioning to the list (maps). AddressListGeoPtr->erase(AddressListIndex); AddressListGeoPtr->insert(std::make_pair(AddressListIndex, txtGeo->GetValue())); // Add the Timezone to the list (maps). AddressListTimezonePtr->erase(AddressListIndex); AddressListTimezonePtr->insert(std::make_pair(AddressListIndex, txtTimezone->GetValue())); // No need to update type since it will not have changed. //AddressListTypePtr = &AddressListType; // Add the mediatype to the list (maps). AddressListMediatypePtr->erase(AddressListIndex); AddressListMediatypePtr->insert(std::make_pair(AddressListIndex, wxT("text/plain"))); //AddressListMediatypePtr = &AddressListMediatype; //AddressListPrefPtr = &AddressListPref; AddressListPrefPtr->erase(AddressListIndex); if (chkUsePref->IsChecked()){ AddressListPrefPtr->insert(std::make_pair(AddressListIndex, sliPriority->GetValue())); } else { AddressListPrefPtr->insert(std::make_pair(AddressListIndex, 0)); } // Update the form with the new details. longSelected = AddressListCtrlPtr->GetNextItem(longSelected, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (longSelected == -1){ return; } AddressListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 1, txtTownCity->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 2, txtCounty->GetValue()); AddressListCtrlPtr->SetItem(longSelected, 3, txtPostCode->GetValue()); if (chkUsePref->IsChecked()){ AddressListCtrlPtr->SetItem(longSelected, 4, wxString::Format(wxT("%i"), sliPriority->GetValue())); } else { AddressListCtrlPtr->SetItem(longSelected, 4, wxT("")); } this->Close(); } } void frmContactEditorAddress::CloseWindow( wxCommandEvent& event ) { this->Close(); } void frmContactEditorAddress::CopyAddress( wxCommandEvent& event ) { wxString MailingLabel; bool AddComma = FALSE; if (!txtAddress->IsEmpty()){ MailingLabel.Append(txtAddress->GetValue()); AddComma = TRUE; } if (!txtTownCity->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtTownCity->GetValue()); AddComma = TRUE; } if (!txtCounty->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtCounty->GetValue()); AddComma = TRUE; } if (!txtPostCode->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtPostCode->GetValue()); AddComma = TRUE; } if (!txtCountry->IsEmpty()){ if(AddComma == TRUE){ MailingLabel.Append(wxT(",\n")); AddComma = FALSE; } MailingLabel.Append(txtCountry->GetValue()); AddComma = TRUE; } txtLabel->SetValue(MailingLabel); } void frmContactEditorAddress::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 Address")); } else if (EditMode == TRUE){ EditorMode = TRUE; btnAction->SetLabel(_("Modify")); this->SetTitle(_("Modify Address")); wxString strValue; std::map::iterator intiter; std::map::iterator striter; // Load the data into the form. striter = AddressListPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ txtAddress->SetValue(striter->second); } striter = AddressListTownPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ txtTownCity->SetValue(striter->second); } striter = AddressListCountyPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ txtCounty->SetValue(striter->second); } striter = AddressListPostCodePtr->find(AddressListIndex); if (striter->first == AddressListIndex){ txtPostCode->SetValue(striter->second); } striter = AddressListCountryPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ txtCountry->SetValue(striter->second); } //CaptureString(&strValue, TRUE); //->Replace(wxT("\;"), wxT("\;;"), TRUE); // Setup the Slider. intiter = AddressListPrefPtr->find(AddressListIndex); if (intiter->first == AddressListIndex && intiter->second > 0){ sliPriority->SetValue(intiter->second); sliPriority->Enable(); chkUsePref->SetValue(TRUE); } // Setup the Label. striter = AddressListLabelPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ strValue = striter->second; } txtLabel->SetValue(strValue); // Setup the Language, Geographic position and timezone. striter = AddressListLangPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ strValue = striter->second; } cmbLanguage->SetValue(strValue); striter = AddressListGeoPtr->find(AddressListIndex); if (striter->first == AddressListIndex){ strValue = striter->second; } txtGeo->SetValue(strValue); striter = AddressListTimezonePtr->find(AddressListIndex); if (striter->first == AddressListIndex){ strValue = striter->second; } txtTimezone->SetValue(strValue); } EditSectionType = SectType; } void frmContactEditorAddress::SetupPointers( std::map *AddressList, std::map *AddressListTown, std::map *AddressListCounty, std::map *AddressListPostCode, std::map *AddressListCountry, std::map *AddressListLabel, std::map *AddressListLang, std::map *AddressListAltID, std::map *AddressListPID, std::map *AddressListTokens, std::map *AddressListGeo, std::map *AddressListTimezone, std::map *AddressListType, std::map *AddressListMediatype, std::map *AddressListPref, wxListCtrl *AddressListCtrl, int AddressIndex ) { AddressListPtr = AddressList; AddressListTownPtr = AddressListTown; AddressListCountyPtr = AddressListCounty; AddressListPostCodePtr = AddressListPostCode; AddressListCountryPtr = AddressListCountry; AddressListLabelPtr = AddressListLabel; AddressListLangPtr = AddressListLang; AddressListAltIDPtr = AddressListAltID; AddressListPIDPtr = AddressListPID; AddressListTokensPtr = AddressListTokens; AddressListGeoPtr = AddressListGeo; AddressListTimezonePtr = AddressListTimezone; AddressListTypePtr = AddressListType; AddressListMediatypePtr = AddressListMediatype; AddressListPrefPtr = AddressListPref; AddressListCtrlPtr = AddressListCtrl; AddressListIndex = AddressIndex; }