Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorCalAdr.cpp
1 // frmContactEditorCalAdr.cpp - frmContactEditorCalAdr 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 "frmContactEditorCalAdr.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCalAdr::frmContactEditorCalAdr( wxWindow* parent )
24 :
25 frmContactEditorCalAdrADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         szrGeneral->Layout();
34         
35         cmbType->Append(wxT(""));
36         cmbType->Append(_("Home"));
37         cmbType->Append(_("Work"));
38         
39 }
41 void frmContactEditorCalAdr::ProcessAction( wxCommandEvent& event )
42 {
43         
44         // Process action.
45         
46         long ListCtrlIndex;
47         
48         if (EditorMode == FALSE){
50                 wxString strValue;
51         
52                 // Setup Calendar Address.
53                 
54                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
56                 strValue.Clear();
57                 
58                 strValue = cmbType->GetString(cmbType->GetSelection());
60                 // Setup Calendar Type.
62                 if (strValue == _("Home")) {
63                 
64                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
65                 
66                 } else if (strValue == _("Work")) {
67                 
68                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
69                 
70                 } else {
71                 
72                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("")));
73                 
74                 }
75                 
76                 // Setup Calendar Priority.
77                 
78                 if (priorityCtrl->IsPriorityChecked()){
79                 
80                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
81                 
82                 } else {
83                 
84                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
85                 
86                 }
87                 
88                 // Add to form.
89                 
90                 wxListItem coldata;
91                 
92                 coldata.SetId(CalAdrListIndex);
93                 coldata.SetData(CalAdrListIndex);
94                 coldata.SetText(txtAddress->GetValue());
95                 ListCtrlIndex = CalAdrListCtrlPtr->InsertItem(coldata);
96                 
97                 CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 1, strValue);
98                 
99                 if (priorityCtrl->IsPriorityChecked()){
100                 
101                         CalAdrListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
102                 
103                 }
104                 
105                 this->Close();
106                 
107         } else if (EditorMode == TRUE) {
108         
109                 long longSelected = -1;
110                 wxString strValue;      
111         
112                 // Update Category Name.
113                 
114                 CalAdrListPtr->erase(CalAdrListIndex);
115                 CalAdrListPtr->insert(std::make_pair(CalAdrListIndex, txtAddress->GetValue()));
116                 
117                 // Update Category Type.
118                 
119                 CalAdrListTypePtr->erase(CalAdrListIndex);
120                 
121                 strValue.Clear();
122                 strValue = cmbType->GetString(cmbType->GetSelection());
123                 
124                 if (strValue == _("Home")) {
125                 
126                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("home")));
127                 
128                 } else if (strValue == _("Work")) {
129                 
130                         CalAdrListTypePtr->insert(std::make_pair(CalAdrListIndex, wxT("work")));
131                 
132                 }               
133                 
134                 // Update Category Priority.
135                 
136                 CalAdrListPrefPtr->erase(CalAdrListIndex);
137                 
138                 if (priorityCtrl->IsPriorityChecked()){
139                 
140                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, priorityCtrl->GetValue()));
141                 
142                 } else {
143                 
144                         CalAdrListPrefPtr->insert(std::make_pair(CalAdrListIndex, 0));
145                 
146                 }
147                 
148                 // Update form.
149                 
150                 longSelected = CalAdrListCtrlPtr->GetNextItem(longSelected, 
151                         wxLIST_NEXT_ALL,
152                         wxLIST_STATE_SELECTED);
153                         
154                 if (longSelected == -1){
155                         return;
156                 }               
157                 
158                 CalAdrListCtrlPtr->SetItem(longSelected, 0, txtAddress->GetValue());
159                 CalAdrListCtrlPtr->SetItem(longSelected, 1, strValue);          
160                 
161                 if (priorityCtrl->IsPriorityChecked()){
162                 
163                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
164                 
165                 } else {
166                 
167                         CalAdrListCtrlPtr->SetItem(longSelected, 2, wxT(""));
168                 
169                 }
170                 
171                 this->Close();  
172         
173         }
174         
177 void frmContactEditorCalAdr::SetEditorMode(bool EditMode)
179         
180         // Set the editor mode.
181         
182         // Set if the editor is adding or editing an address.
183         // FALSE = Add
184         // TRUE = Edit
185         
186         if (EditMode == FALSE){
187         
188                 EditorMode = FALSE;
189                 btnAction->SetLabel(_("Add"));
190                 this->SetTitle(_("Add Calendar Address"));
191         
192         } else if (EditMode == TRUE){
193         
194                 EditorMode = TRUE;
195                 btnAction->SetLabel(_("Modify"));
196                 this->SetTitle(_("Modify Calendar Address"));
197                 
198                 std::map<int,int>::iterator intiter;
199                 std::map<int,wxString>::iterator striter;               
200                 wxString strValue;              
201                         
202                 // Get the organisation name.
203                 
204                 striter = CalAdrListPtr->find(CalAdrListIndex);
205                  
206                 if (striter->first == CalAdrListIndex){
207                 
208                         strValue = striter->second;
209                 
210                 }
211                 
212                 txtAddress->SetValue(strValue);
213                 
214                 strValue.Clear();
215                 
216                 // Get the type.
217                 
218                 striter = CalAdrListTypePtr->find(CalAdrListIndex);     
219                 
220                 if (striter->first == CalAdrListIndex && 
221                         striter != CalAdrListTypePtr->end()){
222                 
223                         strValue = striter->second;
224                 
225                 }
226                 
227                 if (strValue == wxT("home")){
228                 
229                         cmbType->SetSelection(1);
230                 
231                 } else if (strValue == wxT("work")){
232                 
233                         cmbType->SetSelection(2);       
234                 
235                 } else {
236                 
237                         cmbType->SetSelection(0);
238                 
239                 }
240                 
241                 // Get the organisation priority.
242                 
243                 intiter = CalAdrListPrefPtr->find(CalAdrListIndex);
244                 
245                 if (intiter->first == CalAdrListIndex && intiter->second > 0 &&
246                         intiter != CalAdrListPrefPtr->end()){
247                 
248                         priorityCtrl->SetValue(intiter->second);
249                         priorityCtrl->EnablePriority(true);
250                 
251                 }
252                 
253         }
254                 
257 void frmContactEditorCalAdr::CloseWindow( wxCommandEvent& event )
259         
260         // Close the window.
261         
262         this->Close();
263         
266 void frmContactEditorCalAdr::SetupPointers(std::map<int, wxString> *CalAdrList,
267         std::map<int, wxString> *CalAdrListAltID,
268         std::map<int, wxString> *CalAdrListPID,
269         std::map<int, wxString> *CalAdrListType,
270         std::map<int, wxString> *CalAdrListTokens,
271         std::map<int, int> *CalAdrListPref,
272         wxListCtrl *CalAdrListCtrl,
273         int CalAdrIndex )
276         // Setup the pointers.
277         
278         CalAdrListPtr = CalAdrList;
279         CalAdrListAltIDPtr = CalAdrListAltID;
280         CalAdrListPIDPtr = CalAdrListPID;
281         CalAdrListTypePtr = CalAdrListType;
282         CalAdrListTokensPtr = CalAdrListTokens;
283         CalAdrListPrefPtr = CalAdrListPref;
284         CalAdrListCtrlPtr = CalAdrListCtrl;
285         CalAdrListIndex = CalAdrIndex;
286         
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