1 // frmContactEditorVendor.cpp - frmContactEditorVendor form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "frmContactEditorVendor.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorVendor::frmContactEditorVendor( wxWindow* parent )
25 frmContactEditorVendorADT( parent )
30 void frmContactEditorVendor::SetEditorMode(bool EditMode)
33 // Set if the editor is adding or editing an address.
37 if (EditMode == FALSE){
40 btnAction->SetLabel(_("Add"));
41 this->SetTitle(_("Add Vendor Namespace"));
43 } else if (EditMode == TRUE){
46 btnAction->SetLabel(_("Modify"));
47 this->SetTitle(_("Add Vendor Namespace"));
49 std::map<int,int>::iterator intiter;
50 std::map<int,wxString>::iterator striter;
53 // Get the vendor PEN.
55 striter = VendorListPENPtr->find(VendorListIndex);
57 if (striter->first == VendorListIndex){
59 strValue = striter->second;
63 txtPEN->SetValue(strValue);
67 // Get the vendor element.
69 striter = VendorListElementPtr->find(VendorListIndex);
71 if (striter->first == VendorListIndex &&
72 striter != VendorListElementPtr->end()){
74 strValue = striter->second;
78 txtElement->SetValue(strValue);
82 // Get the vendor value.
84 striter = VendorListPtr->find(VendorListIndex);
86 if (striter->first == VendorListIndex &&
87 striter != VendorListPtr->end()){
89 strValue = striter->second;
93 txtValue->SetValue(strValue);
101 void frmContactEditorVendor::ProcessAction( wxCommandEvent& event )
106 if (EditorMode == FALSE){
113 coldata.SetId(VendorListIndex);
114 coldata.SetData(VendorListIndex);
115 ListCtrlIndex = VendorListCtrlPtr->InsertItem(coldata);
119 strValue = txtPEN->GetValue();
120 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
122 // Get Vendor Element.
124 strValue = txtElement->GetValue();
125 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
129 strValue = txtValue->GetValue();
130 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
134 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
136 VendorListCtrlPtr->SetItem(ListCtrlIndex, 0, strVNDID);
140 } else if (EditorMode == TRUE){
142 long longSelected = -1;
146 longSelected = VendorListCtrlPtr->GetNextItem(longSelected,
148 wxLIST_STATE_SELECTED);
150 if (longSelected == -1){
154 // Update Vendor PEN.
156 VendorListPENPtr->erase(VendorListIndex);
157 strValue = txtPEN->GetValue();
158 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
160 // Update Vendor Element.
162 VendorListElementPtr->erase(VendorListIndex);
163 strValue = txtValue->GetValue();
164 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
166 // Update Vendor Value.
168 VendorListPtr->erase(VendorListIndex);
169 strValue = txtValue->GetValue();
170 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
174 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
175 VendorListCtrlPtr->SetItem(longSelected, 0, strVNDID);
182 void frmContactEditorVendor::SetupPointers( std::map<int, wxString> *VendorList,
183 std::map<int, wxString> *VendorListPEN,
184 std::map<int, wxString> *VendorListElement,
185 wxListCtrl *VendorListCtrl,
188 // Setup the pointers.
190 VendorListPtr = VendorList;
191 VendorListPENPtr = VendorListPEN;
192 VendorListElementPtr = VendorListElement;
193 VendorListCtrlPtr = VendorListCtrl;
194 VendorListIndex = VendorIndex;
198 void frmContactEditorVendor::CloseWindow( wxCommandEvent& event )