Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor: Stop XAB crashing when pressing Modify/Delete
[xestiaab/.git] / source / contacteditor / frmContactEditorTitles.cpp
1 // frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
26 :
27 frmContactEditorTitlesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35 }
37 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
38 {
39         
40         // Process action.
41         
42         // Set if the editor is adding or editing an address.
43         // FALSE = Add
44         // TRUE = Edit
46         long ListCtrlIndex;
47         
48         if (EditorMode == FALSE){
49         
50                 wxString strValue;
51                 
52                 // Get the website address.
53                 
54                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
55                 
56                 // Get the type of website.
57                 
58                 if (EditSectionType == CE_GENERAL){
59                 
60                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
61                 
62                 } else if (EditSectionType == CE_HOME) {
63                 
64                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
65                 
66                 } else if (EditSectionType == CE_WORK) {
67                 
68                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
69                 
70                 }
71                 
72                 // Add the website priority.
73                 
74                 if (priorityCtrl->IsPriorityChecked()){
75                 
76                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
77                 
78                 } else {
79                 
80                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));          
81                 
82                 }
83                 
84                 // Add to the form.
85                 
86                 wxListItem coldata;
87                 
88                 coldata.SetId(TitlesListIndex);
89                 coldata.SetData(TitlesListIndex);               
90                 coldata.SetText(txtTitle->GetValue());
91                 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
92                 
93                 if (priorityCtrl->IsPriorityChecked()){
94                 
95                         TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
96                 
97                 }               
98         
99                 this->Close();          
100         
101         } else {
102         
103                 // Update the title.
104                 long longSelected = -1;         
105                 wxString strValue;
106                 TitlesListPtr->erase(TitlesListIndex);
107                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
108                 
109                 // Update the slider priority.
110                 
111                 TitlesListPrefPtr->erase(TitlesListIndex);
112                 
113                 if (priorityCtrl->IsPriorityChecked()){
114                 
115                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
116                 
117                 } else {
118                 
119                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
120                 
121                 }               
122                 
123                 // Update the form.
124                 
125                 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected, 
126                         wxLIST_NEXT_ALL,
127                         wxLIST_STATE_SELECTED);
128                         
129                 if (longSelected == -1){
130                         return;
131                 }               
132                 
133                 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
134                 
135                 if (priorityCtrl->IsPriorityChecked()){
136                 
137                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
138                 
139                 } else {
140                 
141                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
142                 
143                 }               
144         
145                 this->Close();
146         
147         }
150 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
152         
153         // Set the editor mode.
154         
155         // Set if the editor is adding or editing an address.
156         // FALSE = Add
157         // TRUE = Edit
158         
159         if (EditMode == FALSE){
160         
161                 EditorMode = FALSE;
162                 btnAction->SetLabel(_("Add"));
163                 this->SetTitle(_("Add Title"));
164         
165         } else if (EditMode == TRUE){
166         
167                 EditorMode = TRUE;
168                 btnAction->SetLabel(_("Modify"));
169                 this->SetTitle(_("Modify Title"));
170                 
171                 std::map<int,int>::iterator intiter;
172                 std::map<int,wxString>::iterator striter;               
173                 wxString strValue;
174                 
175                 // Load the data into the form. Get the website.
176                 
177                 striter = TitlesListPtr->find(TitlesListIndex);
178                  
179                 if (striter->first == TitlesListIndex &&
180                         striter != TitlesListPtr->end()){
181                 
182                         strValue = striter->second;
183                 
184                 }
185                 
186                 txtTitle->SetValue(strValue);
187                 
188                 strValue.Clear();
189                 
190                 // Get the website priority.
191                 
192                 intiter = TitlesListPrefPtr->find(TitlesListIndex);
193                 
194                 if (intiter->first == TitlesListIndex && intiter->second > 0 &&
195                         intiter != TitlesListPrefPtr->end()){
196                 
197                         priorityCtrl->SetValue(intiter->second);
198                         priorityCtrl->EnablePriority(true);
199                 
200                 }       
201                 
202         }
203         
204         EditSectionType = SectType;
205                 
208 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
210         
211         // Close the window.
212         
213         this->Close();
214         
217 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
218         std::map<int, wxString> *TitlesListLanguage,
219         std::map<int, wxString> *TitlesListAltID,
220         std::map<int, wxString> *TitlesListPID,
221         std::map<int, wxString> *TitlesListType,
222         std::map<int, wxString> *TitlesListTokens,
223         std::map<int, int> *TitlesListPref,
224         wxListCtrl *TitlesListCtrl,
225         int TitlesIndex )
228         // Setup the pointers.
229         
230         TitlesListPtr = TitlesList;
231         TitlesListLanguagePtr = TitlesListLanguage;
232         TitlesListAltIDPtr = TitlesListAltID;
233         TitlesListPIDPtr = TitlesListPID;
234         TitlesListTypePtr = TitlesListType;
235         TitlesListTokensPtr = TitlesListTokens;
236         TitlesListPrefPtr = TitlesListPref;
237         TitlesListCtrlPtr = TitlesListCtrl;
238         TitlesListIndex = TitlesIndex;
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