1 #include "frmContactEditorOrganisations.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorOrganisations::frmContactEditorOrganisations( wxWindow* parent )
7 frmContactEditorOrganisationsADT( parent )
10 sliPriority->Disable();
13 void frmContactEditorOrganisations::UpdateSortAs( wxCommandEvent& event )
16 // Clear out the options for the combo box.
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.
24 wxStringTokenizer tknOrg(txtOrganisation->GetValue(), wxT(" "));
29 if (tknOrg.CountTokens() > 1){
31 strFirst = tknOrg.GetNextToken();
33 while (tknOrg.HasMoreTokens()){
35 strArrange.Append(tknOrg.GetNextToken());
37 if (tknOrg.CountTokens() != 0){
38 strArrange.Append(wxT(" "));
43 strArrFinal.Append(strArrange);
44 strArrFinal.Append(wxT(", "));
45 strArrFinal.Append(strFirst);
46 cmbSortAs->Append(strArrFinal);
52 void frmContactEditorOrganisations::EnablePriority( wxCommandEvent& event )
54 if (chkUsePref->IsChecked()){
55 sliPriority->Enable();
57 sliPriority->Disable();
61 void frmContactEditorOrganisations::ProcessAction( wxCommandEvent& event )
66 if (EditorMode == FALSE){
70 // Setup Organisation Name.
72 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
74 // Setup Organisation Type.
76 if (EditSectionType == CE_GENERAL){
78 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("")));
80 } else if (EditSectionType == CE_HOME) {
82 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("home")));
84 } else if (EditSectionType == CE_WORK) {
86 OrganisationListTypePtr->insert(std::make_pair(OrganisationListIndex, wxT("work")));
90 // Setup Organisation SortAs.
93 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
95 // Setup Organisation Priority.
97 if (chkUsePref->IsChecked()){
99 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
103 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
111 coldata.SetId(OrganisationListIndex);
112 coldata.SetData(OrganisationListIndex);
113 coldata.SetText(txtOrganisation->GetValue());
114 ListCtrlIndex = OrganisationListCtrlPtr->InsertItem(coldata);
116 if (chkUsePref->IsChecked()){
118 OrganisationListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
124 } else if (EditorMode == TRUE) {
126 long longSelected = -1;
129 // Update Organisation Name.
131 OrganisationListPtr->erase(OrganisationListIndex);
132 OrganisationListPtr->insert(std::make_pair(OrganisationListIndex, txtOrganisation->GetValue()));
134 // Update Organisation SortAs.
137 OrganisationListSortAsPtr->erase(OrganisationListIndex);
138 OrganisationListSortAsPtr->insert(std::make_pair(OrganisationListIndex, cmbSortAs->GetValue()));
140 // Update Organisation Priority.
142 OrganisationListPrefPtr->erase(OrganisationListIndex);
144 if (chkUsePref->IsChecked()){
146 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, sliPriority->GetValue()));
150 OrganisationListPrefPtr->insert(std::make_pair(OrganisationListIndex, 0));
156 longSelected = OrganisationListCtrlPtr->GetNextItem(longSelected,
158 wxLIST_STATE_SELECTED);
160 if (longSelected == -1){
164 OrganisationListCtrlPtr->SetItem(longSelected, 0, txtOrganisation->GetValue());
166 if (chkUsePref->IsChecked()){
168 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
172 OrganisationListCtrlPtr->SetItem(longSelected, 1, wxT(""));
182 void frmContactEditorOrganisations::SetEditorMode(bool EditMode, SectionType SectType)
184 // Set if the editor is adding or editing an address.
188 if (EditMode == FALSE){
191 btnAction->SetLabel(_("Add"));
192 this->SetTitle(_("Add Organisation"));
194 } else if (EditMode == TRUE){
197 btnAction->SetLabel(_("Modify"));
198 this->SetTitle(_("Modify Organisation"));
200 // Load the data into the form.
202 std::map<int,int>::iterator intiter;
203 std::map<int,wxString>::iterator striter;
206 // Get the organisation name.
208 striter = OrganisationListPtr->find(OrganisationListIndex);
210 if (striter->first == OrganisationListIndex){
212 strValue = striter->second;
216 txtOrganisation->SetValue(strValue);
220 // Get the organisation sort as.
222 striter = OrganisationListSortAsPtr->find(OrganisationListIndex);
224 if (striter->first == OrganisationListIndex){
226 strValue = striter->second;
230 cmbSortAs->SetValue(strValue);
232 // Get the organisation priority.
234 intiter = OrganisationListPrefPtr->find(OrganisationListIndex);
236 if (intiter->first == OrganisationListIndex && intiter->second > 0){
238 sliPriority->SetValue(intiter->second);
239 sliPriority->Enable();
240 chkUsePref->SetValue(TRUE);
246 EditSectionType = SectType;
250 void frmContactEditorOrganisations::CloseWindow( wxCommandEvent& event )
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;