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)
32 // Set if the editor is adding or editing an address.
36 if (EditMode == FALSE){
39 btnAction->SetLabel(_("Add"));
40 this->SetTitle(_("Add Vendor Namespace"));
42 } else if (EditMode == TRUE){
45 btnAction->SetLabel(_("Modify"));
46 this->SetTitle(_("Add Vendor Namespace"));
48 std::map<int,int>::iterator intiter;
49 std::map<int,wxString>::iterator striter;
52 // Get the vendor PEN.
54 striter = VendorListPENPtr->find(VendorListIndex);
56 if (striter->first == VendorListIndex){
58 strValue = striter->second;
62 txtPEN->SetValue(strValue);
66 // Get the vendor element.
68 striter = VendorListElementPtr->find(VendorListIndex);
70 if (striter->first == VendorListIndex){
72 strValue = striter->second;
76 txtElement->SetValue(strValue);
80 // Get the vendor value.
82 striter = VendorListPtr->find(VendorListIndex);
84 if (striter->first == VendorListIndex){
86 strValue = striter->second;
90 txtValue->SetValue(strValue);
98 void frmContactEditorVendor::ProcessAction( wxCommandEvent& event )
101 if (EditorMode == FALSE){
108 coldata.SetId(VendorListIndex);
109 coldata.SetData(VendorListIndex);
110 ListCtrlIndex = VendorListCtrlPtr->InsertItem(coldata);
114 strValue = txtPEN->GetValue();
115 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
117 // Get Vendor Element.
119 strValue = txtElement->GetValue();
120 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
124 strValue = txtValue->GetValue();
125 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
129 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
131 VendorListCtrlPtr->SetItem(ListCtrlIndex, 0, strVNDID);
135 } else if (EditorMode == TRUE){
137 long longSelected = -1;
141 longSelected = VendorListCtrlPtr->GetNextItem(longSelected,
143 wxLIST_STATE_SELECTED);
145 if (longSelected == -1){
149 // Update Vendor PEN.
151 VendorListPENPtr->erase(VendorListIndex);
152 strValue = txtPEN->GetValue();
153 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
155 // Update Vendor Element.
157 VendorListElementPtr->erase(VendorListIndex);
158 strValue = txtValue->GetValue();
159 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
161 // Update Vendor Value.
163 VendorListPtr->erase(VendorListIndex);
164 strValue = txtValue->GetValue();
165 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
169 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
170 VendorListCtrlPtr->SetItem(longSelected, 0, strVNDID);
177 void frmContactEditorVendor::SetupPointers( std::map<int, wxString> *VendorList,
178 std::map<int, wxString> *VendorListPEN,
179 std::map<int, wxString> *VendorListElement,
180 wxListCtrl *VendorListCtrl,
184 VendorListPtr = VendorList;
185 VendorListPENPtr = VendorListPEN;
186 VendorListElementPtr = VendorListElement;
187 VendorListCtrlPtr = VendorListCtrl;
188 VendorListIndex = VendorIndex;
192 void frmContactEditorVendor::CloseWindow( wxCommandEvent& event )