1 #include "frmContactEditorCategory.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent )
7 frmContactEditorCategoryADT( parent )
10 sliPriority->Disable();
12 cmbType->Append(wxT(""));
13 cmbType->Append(_("Home"));
14 cmbType->Append(_("Work"));
17 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
19 if (chkUsePref->IsChecked()){
20 sliPriority->Enable();
22 sliPriority->Disable();
26 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
31 if (EditorMode == FALSE){
35 // Setup Organisation Name.
37 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
41 strValue = cmbType->GetString(cmbType->GetSelection());
43 // Setup Category Type.
45 if (strValue == _("Home")) {
47 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
49 } else if (strValue == _("Work")) {
51 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
55 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
59 // Setup Category Priority.
61 if (chkUsePref->IsChecked()){
63 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
67 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
75 coldata.SetId(CategoryListIndex);
76 coldata.SetData(CategoryListIndex);
77 coldata.SetText(txtCategory->GetValue());
78 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
80 if (chkUsePref->IsChecked()){
82 CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
88 } else if (EditorMode == TRUE) {
90 long longSelected = -1;
93 // Update Category Name.
95 CategoryListPtr->erase(CategoryListIndex);
96 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
98 // Update Category Type.
100 CategoryListTypePtr->erase(CategoryListIndex);
102 strValue = cmbType->GetString(cmbType->GetSelection());
104 if (strValue == _("Home")) {
106 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
108 } else if (strValue == _("Work")) {
110 CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
114 // Update Category Priority.
116 CategoryListPrefPtr->erase(CategoryListIndex);
118 if (chkUsePref->IsChecked()){
120 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
124 CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
130 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected,
132 wxLIST_STATE_SELECTED);
134 if (longSelected == -1){
138 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
140 if (chkUsePref->IsChecked()){
142 CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
146 CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
156 void frmContactEditorCategory::SetEditorMode(bool EditMode)
158 // Set if the editor is adding or editing an address.
162 if (EditMode == FALSE){
165 btnAction->SetLabel(_("Add"));
166 this->SetTitle(_("Add Category"));
168 } else if (EditMode == TRUE){
171 btnAction->SetLabel(_("Modify"));
172 this->SetTitle(_("Modify Category"));
174 // Load the data into the form.
176 std::map<int,int>::iterator intiter;
177 std::map<int,wxString>::iterator striter;
180 // Get the organisation name.
182 striter = CategoryListPtr->find(CategoryListIndex);
184 if (striter->first == CategoryListIndex){
186 strValue = striter->second;
190 txtCategory->SetValue(strValue);
196 striter = CategoryListTypePtr->find(CategoryListIndex);
198 if (striter->first == CategoryListIndex){
200 strValue = striter->second;
204 if (strValue == wxT("home")){
206 cmbType->SetSelection(1);
208 } else if (strValue == wxT("work")){
210 cmbType->SetSelection(2);
214 cmbType->SetSelection(0);
218 // Get the organisation priority.
220 intiter = CategoryListPrefPtr->find(CategoryListIndex);
222 if (intiter->first == CategoryListIndex && intiter->second > 0){
224 sliPriority->SetValue(intiter->second);
225 sliPriority->Enable();
226 chkUsePref->SetValue(TRUE);
234 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
239 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
240 std::map<int, wxString> *CategoryListAltID,
241 std::map<int, wxString> *CategoryListPID,
242 std::map<int, wxString> *CategoryListType,
243 std::map<int, wxString> *CategoryListTokens,
244 std::map<int, int> *CategoryListPref,
245 wxListCtrl *CategoryListCtrl,
249 CategoryListPtr = CategoryList;
250 //CategoryListSortAsPtr = CategoryListSortAs;
251 CategoryListAltIDPtr = CategoryListAltID;
252 CategoryListPIDPtr = CategoryListPID;
253 CategoryListTypePtr = CategoryListType;
254 CategoryListTokensPtr = CategoryListTokens;
255 CategoryListPrefPtr = CategoryListPref;
256 CategoryListCtrlPtr = CategoryListCtrl;
257 CategoryListIndex = CategoryIndex;