// frmContactEditorVendor.cpp - frmContactEditorVendor 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 "frmContactEditorVendor.h"
#include
#include "../common/textprocessing.h"
frmContactEditorVendor::frmContactEditorVendor( wxWindow* parent )
:
frmContactEditorVendorADT( parent )
{
}
void frmContactEditorVendor::SetEditorMode(bool EditMode)
{
// 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 Vendor Namespace"));
} else if (EditMode == TRUE){
EditorMode = TRUE;
btnAction->SetLabel(_("Modify"));
this->SetTitle(_("Add Vendor Namespace"));
std::map::iterator intiter;
std::map::iterator striter;
wxString strValue;
// Get the vendor PEN.
striter = VendorListPENPtr->find(VendorListIndex);
if (striter->first == VendorListIndex){
strValue = striter->second;
}
txtPEN->SetValue(strValue);
strValue.Clear();
// Get the vendor element.
striter = VendorListElementPtr->find(VendorListIndex);
if (striter->first == VendorListIndex){
strValue = striter->second;
}
txtElement->SetValue(strValue);
strValue.Clear();
// Get the vendor value.
striter = VendorListPtr->find(VendorListIndex);
if (striter->first == VendorListIndex){
strValue = striter->second;
}
txtValue->SetValue(strValue);
strValue.Clear();
}
}
void frmContactEditorVendor::ProcessAction( wxCommandEvent& event )
{
if (EditorMode == FALSE){
wxString strValue;
wxString strVNDID;
wxListItem coldata;
long ListCtrlIndex;
coldata.SetId(VendorListIndex);
coldata.SetData(VendorListIndex);
ListCtrlIndex = VendorListCtrlPtr->InsertItem(coldata);
// Get Vendor PEN.
strValue = txtPEN->GetValue();
VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
// Get Vendor Element.
strValue = txtElement->GetValue();
VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
// Get Vendor Value.
strValue = txtValue->GetValue();
VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
// Update form.
strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
VendorListCtrlPtr->SetItem(ListCtrlIndex, 0, strVNDID);
this->Close();
} else if (EditorMode == TRUE){
long longSelected = -1;
wxString strValue;
wxString strVNDID;
longSelected = VendorListCtrlPtr->GetNextItem(longSelected,
wxLIST_NEXT_ALL,
wxLIST_STATE_SELECTED);
if (longSelected == -1){
return;
}
// Update Vendor PEN.
VendorListPENPtr->erase(VendorListIndex);
strValue = txtPEN->GetValue();
VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
// Update Vendor Element.
VendorListElementPtr->erase(VendorListIndex);
strValue = txtValue->GetValue();
VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
// Update Vendor Value.
VendorListPtr->erase(VendorListIndex);
strValue = txtValue->GetValue();
VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
// Update form.
strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
VendorListCtrlPtr->SetItem(longSelected, 0, strVNDID);
this->Close();
}
}
void frmContactEditorVendor::SetupPointers( std::map *VendorList,
std::map *VendorListPEN,
std::map *VendorListElement,
wxListCtrl *VendorListCtrl,
int VendorIndex )
{
VendorListPtr = VendorList;
VendorListPENPtr = VendorListPEN;
VendorListElementPtr = VendorListElement;
VendorListCtrlPtr = VendorListCtrl;
VendorListIndex = VendorIndex;
}
void frmContactEditorVendor::CloseWindow( wxCommandEvent& event )
{
this->Close();
}