Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorOrganisations.cpp
1 #include "frmContactEditorOrganisations.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorOrganisations::frmContactEditorOrganisations( wxWindow* parent )
6 :
7 frmContactEditorOrganisationsADT( parent )
8 {
9         EditorMode = FALSE;
10         sliPriority->Disable();
11 }
13 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
14 {
16         // Clear out the options for the combo box.
17         
18         cmbSortAs->Clear();
19         cmbSortAs->Append(txtOrganisation->GetValue()); 
21         // See if there are more than one word, if not leave drop down
22         // with the default organisation name.
23         
24         wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
25         wxString strArrange;
26         wxString strFirst;
27         wxString strArrFinal;
28         
29         if (tknOrg.CountTokens() > 1){
30         
31                 strFirst = tknOrg.GetNextToken();
32                 
33                 while (tknOrg.HasMoreTokens()){
34                 
35                         strArrange.Append(tknOrg.GetNextToken());
36                         
37                         if (tknOrg.CountTokens() != 0){
38                                 strArrange.Append(wxT(" "));
39                         }
40                 
41                 }
42         
43                 strArrFinal.Append(strArrange);
44                 strArrFinal.Append(wxT(", "));
45                 strArrFinal.Append(strFirst);
46                 cmbSortAs->Append(strArrFinal);
47         
48         }
50 }
52 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
53 {
54         if (chkUsePref->IsChecked()){
55                 sliPriority->Enable();
56         } else {
57                 sliPriority->Disable();
58         }
59 }
61 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
62 {
64         long ListCtrlIndex;
65         
66         if (EditorMode == FALSE){
68                 wxString strValue;
69         
70                 // Setup Organisation Name.
71                 
72                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
74                 // Setup Organisation Type.
76                 if (EditSectionType == CE_GENERAL){
77                 
78                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
79                 
80                 } else if (EditSectionType == CE_HOME) {
81                 
82                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
83                 
84                 } else if (EditSectionType == CE_WORK) {
85                 
86                         OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
87                 
88                 }
89                 
90                 // Setup Organisation SortAs.
91                 
92                 strValue.Clear();
93                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
94                 
95                 // Setup Organisation Priority.
96                 
97                 if (chkUsePref->IsChecked()){
98                 
99                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
100                 
101                 } else {
102                 
103                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
104                 
105                 }
106                 
107                 // Add to form.
108                 
109                 wxListItem coldata;
110                 
111                 coldata.SetId(OrganisationListIndex);
112                 coldata.SetData(OrganisationListIndex);
113                 coldata.SetText(txtOrganisation->GetValue());
114                 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
115                 
116                 if (chkUsePref->IsChecked()){
117                 
118                         OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
119                 
120                 }
121                 
122                 this->Close();
123                 
124         } else if (EditorMode == TRUE) {
125         
126                 long longSelected = -1;
127                 wxString strValue;      
128         
129                 // Update Organisation Name.
130                 
131                 OrganisationListPtr->erase(OrganisationListIndex);
132                 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
133                 
134                 // Update Organisation SortAs.
135                 
136                 strValue.Clear();
137                 OrganisationListSortAsPtr->erase(OrganisationListIndex);
138                 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
139                 
140                 // Update Organisation Priority.
141                 
142                 OrganisationListPrefPtr->erase(OrganisationListIndex);
143                 
144                 if (chkUsePref->IsChecked()){
145                 
146                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
147                 
148                 } else {
149                 
150                         OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
151                 
152                 }
153                 
154                 // Update form.
155                 
156                 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected, 
157                         wxLIST_NEXT_ALL,
158                         wxLIST_STATE_SELECTED);
159                         
160                 if (longSelected == -1){
161                         return;
162                 }               
163                 
164                 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
165                 
166                 if (chkUsePref->IsChecked()){
167                 
168                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
169                 
170                 } else {
171                 
172                         OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
173                 
174                 }
175                 
176                 this->Close();  
177         
178         }
182 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
184         // Set if the editor is adding or editing an address.
185         // FALSE = Add
186         // TRUE = Edit
187         
188         if (EditMode == FALSE){
189         
190                 EditorMode = FALSE;
191                 btnAction->SetLabel(_("Add"));
192                 this->SetTitle(_("Add Organisation"));
193         
194         } else if (EditMode == TRUE){
195         
196                 EditorMode = TRUE;
197                 btnAction->SetLabel(_("Modify"));
198                 this->SetTitle(_("Modify Organisation"));               
199                 
200                 // Load the data into the form.
201                 
202                 std::map<int,int>::iterator intiter;
203                 std::map<int,wxString>::iterator striter;               
204                 wxString strValue;              
205                         
206                 // Get the organisation name.
207                 
208                 striter = OrganisationListPtr->find(OrganisationListIndex);
209                  
210                 if (striter->first == OrganisationListIndex){
211                 
212                         strValue = striter->second;
213                 
214                 }
215                 
216                 txtOrganisation->SetValue(strValue);
217                 
218                 strValue.Clear();
219                 
220                 // Get the organisation sort as.
221                 
222                 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
223                  
224                 if (striter->first == OrganisationListIndex){
225                 
226                         strValue = striter->second;
227                 
228                 }
229                 
230                 cmbSortAs->SetValue(strValue);          
231                 
232                 // Get the organisation priority.
233                 
234                 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);         
235                 
236                 if (intiter->first == OrganisationListIndex && intiter->second > 0){
237                 
238                         sliPriority->SetValue(intiter->second);
239                         sliPriority->Enable();
240                         chkUsePref->SetValue(TRUE);
241                 
242                 }
243                 
244         }
245         
246         EditSectionType = SectType;
247         
250 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
252         this->Close();
255 void frmContactEditorOrganisations::SetupPointers(std::map<int, wxString> *OrganisationList,
256         std::map<int, wxString> *OrganisationListLanguage,
257         std::map<int, wxString> *OrganisationListSortAs,                        
258         std::map<int, wxString> *OrganisationListAltID,
259         std::map<int, wxString> *OrganisationListPID,
260         std::map<int, wxString> *OrganisationListType,
261         std::map<int, wxString> *OrganisationListTokens,
262         std::map<int, int> *OrganisationListPref,
263         wxListCtrl *OrganisationListCtrl,
264         int OrganisationIndex )
267         OrganisationListPtr = OrganisationList;
268         OrganisationListLanguagePtr = OrganisationListLanguage;
269         OrganisationListSortAsPtr = OrganisationListSortAs;
270         OrganisationListAltIDPtr = OrganisationListAltID;
271         OrganisationListPIDPtr = OrganisationListPID;
272         OrganisationListTypePtr = OrganisationListType;
273         OrganisationListTokensPtr = OrganisationListTokens;
274         OrganisationListPrefPtr = OrganisationListPref;
275         OrganisationListCtrlPtr = OrganisationListCtrl;
276         OrganisationListIndex = OrganisationIndex;
277         
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