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 &&
71 striter != VendorListElementPtr->end()){
73 strValue = striter->second;
77 txtElement->SetValue(strValue);
81 // Get the vendor value.
83 striter = VendorListPtr->find(VendorListIndex);
85 if (striter->first == VendorListIndex &&
86 striter != VendorListPtr->end()){
88 strValue = striter->second;
92 txtValue->SetValue(strValue);
100 void frmContactEditorVendor::ProcessAction( wxCommandEvent& event )
103 if (EditorMode == FALSE){
110 coldata.SetId(VendorListIndex);
111 coldata.SetData(VendorListIndex);
112 ListCtrlIndex = VendorListCtrlPtr->InsertItem(coldata);
116 strValue = txtPEN->GetValue();
117 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
119 // Get Vendor Element.
121 strValue = txtElement->GetValue();
122 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
126 strValue = txtValue->GetValue();
127 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
131 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
133 VendorListCtrlPtr->SetItem(ListCtrlIndex, 0, strVNDID);
137 } else if (EditorMode == TRUE){
139 long longSelected = -1;
143 longSelected = VendorListCtrlPtr->GetNextItem(longSelected,
145 wxLIST_STATE_SELECTED);
147 if (longSelected == -1){
151 // Update Vendor PEN.
153 VendorListPENPtr->erase(VendorListIndex);
154 strValue = txtPEN->GetValue();
155 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
157 // Update Vendor Element.
159 VendorListElementPtr->erase(VendorListIndex);
160 strValue = txtValue->GetValue();
161 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
163 // Update Vendor Value.
165 VendorListPtr->erase(VendorListIndex);
166 strValue = txtValue->GetValue();
167 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
171 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
172 VendorListCtrlPtr->SetItem(longSelected, 0, strVNDID);
179 void frmContactEditorVendor::SetupPointers( std::map<int, wxString> *VendorList,
180 std::map<int, wxString> *VendorListPEN,
181 std::map<int, wxString> *VendorListElement,
182 wxListCtrl *VendorListCtrl,
186 VendorListPtr = VendorList;
187 VendorListPENPtr = VendorListPEN;
188 VendorListElementPtr = VendorListElement;
189 VendorListCtrlPtr = VendorListCtrl;
190 VendorListIndex = VendorIndex;
194 void frmContactEditorVendor::CloseWindow( wxCommandEvent& event )