Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Fixed potential crash with frmContactEditorVendor in Edit mode.
[xestiaab/.git] / source / contacteditor / frmContactEditorVendor.cpp
1 // frmContactEditorVendor.cpp - frmContactEditorVendor form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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 )
24 :
25 frmContactEditorVendorADT( parent )
26 {
28 }
30 void frmContactEditorVendor::SetEditorMode(bool EditMode)
31 {
32         // Set if the editor is adding or editing an address.
33         // FALSE = Add
34         // TRUE = Edit
35         
36         if (EditMode == FALSE){
37         
38                 EditorMode = FALSE;
39                 btnAction->SetLabel(_("Add"));
40                 this->SetTitle(_("Add Vendor Namespace"));
41         
42         } else if (EditMode == TRUE){
43         
44                 EditorMode = TRUE;
45                 btnAction->SetLabel(_("Modify"));
46                 this->SetTitle(_("Add Vendor Namespace"));
47                 
48                 std::map<int,int>::iterator intiter;
49                 std::map<int,wxString>::iterator striter;               
50                 wxString strValue;
51                 
52                 // Get the vendor PEN.
53                 
54                 striter = VendorListPENPtr->find(VendorListIndex);
55                  
56                 if (striter->first == VendorListIndex){
57                 
58                         strValue = striter->second;
59                 
60                 }
61                 
62                 txtPEN->SetValue(strValue);
63                 
64                 strValue.Clear();
65                 
66                 // Get the vendor element.
68                 striter = VendorListElementPtr->find(VendorListIndex);
69                  
70                 if (striter->first == VendorListIndex &&
71                         striter != VendorListElementPtr->end()){
72                 
73                         strValue = striter->second;
74                 
75                 }
76                 
77                 txtElement->SetValue(strValue);
78                 
79                 strValue.Clear();
80                 
81                 // Get the vendor value.
82                 
83                 striter = VendorListPtr->find(VendorListIndex);
84                  
85                 if (striter->first == VendorListIndex &&
86                         striter != VendorListPtr->end()){
87                 
88                         strValue = striter->second;
89                 
90                 }
92                 txtValue->SetValue(strValue);
93                 
94                 strValue.Clear();               
95                 
96         }
97         
98 }
100 void frmContactEditorVendor::ProcessAction( wxCommandEvent& event )
102         
103         if (EditorMode == FALSE){
105                 wxString strValue;
106                 wxString strVNDID;
107                 wxListItem coldata;     
108                 long ListCtrlIndex;
109                 
110                 coldata.SetId(VendorListIndex);
111                 coldata.SetData(VendorListIndex);
112                 ListCtrlIndex = VendorListCtrlPtr->InsertItem(coldata);         
113                 
114                 // Get Vendor PEN.
115                 
116                 strValue = txtPEN->GetValue();
117                 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));
118                 
119                 // Get Vendor Element.
120                 
121                 strValue = txtElement->GetValue();
122                 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));
123                 
124                 // Get Vendor Value.
125                 
126                 strValue = txtValue->GetValue();
127                 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
128                 
129                 // Update form.
130                 
131                 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();
132                 
133                 VendorListCtrlPtr->SetItem(ListCtrlIndex, 0, strVNDID);
134                 
135                 this->Close();
136                 
137         } else if (EditorMode == TRUE){
139                 long longSelected = -1; 
140                 wxString strValue;
141                 wxString strVNDID;
142                 
143                 longSelected = VendorListCtrlPtr->GetNextItem(longSelected, 
144                         wxLIST_NEXT_ALL,
145                         wxLIST_STATE_SELECTED);
146                         
147                 if (longSelected == -1){
148                         return;
149                 }
150                 
151                 // Update Vendor PEN.
152                 
153                 VendorListPENPtr->erase(VendorListIndex);
154                 strValue = txtPEN->GetValue();
155                 VendorListPENPtr->insert(std::make_pair(VendorListIndex, strValue));            
156                 
157                 // Update Vendor Element.
158                 
159                 VendorListElementPtr->erase(VendorListIndex);
160                 strValue = txtValue->GetValue();
161                 VendorListElementPtr->insert(std::make_pair(VendorListIndex, strValue));                
162                 
163                 // Update Vendor Value.
164                 
165                 VendorListPtr->erase(VendorListIndex);
166                 strValue = txtValue->GetValue();
167                 VendorListPtr->insert(std::make_pair(VendorListIndex, strValue));
168                 
169                 // Update form.
171                 strVNDID = txtPEN->GetValue() + wxT("-") + txtElement->GetValue();              
172                 VendorListCtrlPtr->SetItem(longSelected, 0, strVNDID);
173                 
174                 this->Close();  
175         
176         }
179 void frmContactEditorVendor::SetupPointers( std::map<int, wxString> *VendorList,
180                         std::map<int, wxString> *VendorListPEN,
181                         std::map<int, wxString> *VendorListElement,
182                         wxListCtrl *VendorListCtrl,
183                         int VendorIndex )
186         VendorListPtr = VendorList;
187         VendorListPENPtr = VendorListPEN;
188         VendorListElementPtr = VendorListElement;
189         VendorListCtrlPtr = VendorListCtrl;
190         VendorListIndex = VendorIndex;
191         
194 void frmContactEditorVendor::CloseWindow( wxCommandEvent& event )
196         this->Close();
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy