Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorOrganisations.cpp
1 // frmContactEditorOrganisation.cpp - frmContactEditorOrganisation 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 "frmContactEditorOrganisations.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorOrganisations::frmContactEditorOrganisations( wxWindow* parent )
24 :
25 frmContactEditorOrganisationsADT( 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 }
37 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
38 {
40         // Update the predefined SortAs listings.
41         
42         // Clear out the options for the combo box.
43         
44         cmbSortAs->Clear();
45         cmbSortAs->Append(txtOrganisation->GetValue()); 
47         // See if there are more than one word, if not leave drop down
48         // with the default organisation name.
49         
50         wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
51         wxString strArrange;
52         wxString strFirst;
53         wxString strArrFinal;
54         
55         if (tknOrg.CountTokens() > 1){
56         
57                 strFirst = tknOrg.GetNextToken();
58                 
59                 while (tknOrg.HasMoreTokens()){
60                 
61                         strArrange.Append(tknOrg.GetNextToken());
62                         
63                         if (tknOrg.CountTokens() != 0){
64                                 strArrange.Append(wxT(" "));
65                         }
66                 
67                 }
68         
69                 strArrFinal.Append(strArrange);
70                 strArrFinal.Append(wxT(", "));
71                 strArrFinal.Append(strFirst);
72                 cmbSortAs->Append(strArrFinal);
73         
74         }
76 }
78 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
79 {
81         // Process action.
82         
83         long ListCtrlIndex;
84         
85         if (EditorMode == FALSE){
87                 wxString strValue;
88         
89                 // Setup Organisation Name.
90                 
91                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
93                 // Setup Organisation Type.
95                 if (EditSectionType == CE_GENERAL){
96                 
97                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
98                 
99                 } else if (EditSectionType == CE_HOME) {
100                 
101                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
102                 
103                 } else if (EditSectionType == CE_WORK) {
104                 
105                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
106                 
107                 }
108                 
109                 // Setup Organisation SortAs.
110                 
111                 strValue.Clear();
112                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
113                 
114                 // Setup Organisation Priority.
115                 
116                 if (priorityCtrl->IsPriorityChecked()){
117                 
118                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
119                 
120                 } else {
121                 
122                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
123                 
124                 }
125                 
126                 // Add to form.
127                 
128                 wxListItem coldata;
129                 
130                 coldata.SetId(OrganisationListIndex);
131                 coldata.SetData(OrganisationListIndex);
132                 coldata.SetText(txtOrganisation->GetValue());
133                 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
134                 
135                 if (priorityCtrl->IsPriorityChecked()){
136                 
137                         OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
138                 
139                 }
140                 
141                 this->Close();
142                 
143         } else if (EditorMode == TRUE) {
144         
145                 long longSelected = -1;
146                 wxString strValue;      
147         
148                 // Update Organisation Name.
149                 
150                 OrganisationListPtr->erase(OrganisationListIndex);
151                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
152                 
153                 // Update Organisation SortAs.
154                 
155                 strValue.Clear();
156                 OrganisationListSortAsPtr->erase(OrganisationListIndex);
157                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
158                 
159                 // Update Organisation Priority.
160                 
161                 OrganisationListPrefPtr->erase(OrganisationListIndex);
162                 
163                 if (priorityCtrl->IsPriorityChecked()){
164                 
165                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, priorityCtrl->GetValue()));
166                 
167                 } else {
168                 
169                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
170                 
171                 }
172                 
173                 // Update form.
174                 
175                 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected, 
176                         wxLIST_NEXT_ALL,
177                         wxLIST_STATE_SELECTED);
178                         
179                 if (longSelected == -1){
180                         return;
181                 }               
182                 
183                 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
184                 
185                 if (priorityCtrl->IsPriorityChecked()){
186                 
187                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
188                 
189                 } else {
190                 
191                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
192                 
193                 }
194                 
195                 this->Close();  
196         
197         }
201 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
203         
204         // Set the editor mode.
205         
206         // Set if the editor is adding or editing an address.
207         // FALSE = Add
208         // TRUE = Edit
209         
210         if (EditMode == FALSE){
211         
212                 EditorMode = FALSE;
213                 btnAction->SetLabel(_("Add"));
214                 this->SetTitle(_("Add Organisation"));
215         
216         } else if (EditMode == TRUE){
217         
218                 EditorMode = TRUE;
219                 btnAction->SetLabel(_("Modify"));
220                 this->SetTitle(_("Modify Organisation"));               
221                 
222                 // Load the data into the form.
223                 
224                 std::map<int,int>::iterator intiter;
225                 std::map<int,wxString>::iterator striter;               
226                 wxString strValue;              
227                         
228                 // Get the organisation name.
229                 
230                 striter = OrganisationListPtr->find(OrganisationListIndex);
231                  
232                 if (striter->first == OrganisationListIndex){
233                 
234                         strValue = striter->second;
235                 
236                 }
237                 
238                 txtOrganisation->SetValue(strValue);
239                 
240                 strValue.Clear();
241                 
242                 // Get the organisation sort as.
243                 
244                 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
245                  
246                 if (striter->first == OrganisationListIndex && 
247                   striter != OrganisationListSortAsPtr->end()){
248                 
249                         strValue = striter->second;
250                 
251                 }
252                 
253                 cmbSortAs->SetValue(strValue);          
254                 
255                 // Get the organisation priority.
256                 
257                 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);         
258                 
259                 if (intiter->first == OrganisationListIndex && intiter->second > 0 &&
260                   intiter != OrganisationListPrefPtr->end()){
261                 
262                         priorityCtrl->SetValue(intiter->second);
263                         priorityCtrl->EnablePriority(true);
264                 
265                 }
266                 
267         }
268         
269         EditSectionType = SectType;
270         
273 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
275         
276         // Close the window.
277         
278         this->Close();
279         
282 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
283         std::map<int, wxString> *OrganisationListLanguage,
284         std::map<int, wxString> *OrganisationListSortAs,                        
285         std::map<int, wxString> *OrganisationListAltID,
286         std::map<int, wxString> *OrganisationListPID,
287         std::map<int, wxString> *OrganisationListType,
288         std::map<int, wxString> *OrganisationListTokens,
289         std::map<int, int> *OrganisationListPref,
290         wxListCtrl *OrganisationListCtrl,
291         int OrganisationIndex )
294         // Setup the pointers.
295         
296         OrganisationListPtr = OrganisationList;
297         OrganisationListLanguagePtr = OrganisationListLanguage;
298         OrganisationListSortAsPtr = OrganisationListSortAs;
299         OrganisationListAltIDPtr = OrganisationListAltID;
300         OrganisationListPIDPtr = OrganisationListPID;
301         OrganisationListTypePtr = OrganisationListType;
302         OrganisationListTokensPtr = OrganisationListTokens;
303         OrganisationListPrefPtr = OrganisationListPref;
304         OrganisationListCtrlPtr = OrganisationListCtrl;
305         OrganisationListIndex = OrganisationIndex;
306         
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