Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorCategory.cpp
1 #include "frmContactEditorCategory.h"
2 #include <wx/tokenzr.h>
3 #include "../common/textprocessing.h"
5 frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent )
6 :
7 frmContactEditorCategoryADT( parent )
8 {
9         EditorMode = FALSE;
10         sliPriority->Disable();
12         cmbType->Append(wxT(""));
13         cmbType->Append(_("Home"));
14         cmbType->Append(_("Work"));     
15 }
17 void frmContactEditorCategory::EnablePriority( wxCommandEvent& event )
18 {
19         if (chkUsePref->IsChecked()){
20                 sliPriority->Enable();
21         } else {
22                 sliPriority->Disable();
23         }
24 }
26 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
27 {
29         long ListCtrlIndex;
30         
31         if (EditorMode == FALSE){
33                 wxString strValue;
34         
35                 // Setup Organisation Name.
36                 
37                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
39                 strValue.Clear();
41                 strValue = cmbType->GetString(cmbType->GetSelection());
43                 // Setup Category Type.
45                 if (strValue == _("Home")) {
46                 
47                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
48                 
49                 } else if (strValue == _("Work")) {
50                 
51                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
52                 
53                 } else {
54                 
55                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
56                 
57                 }
58                 
59                 // Setup Category Priority.
60                 
61                 if (chkUsePref->IsChecked()){
62                 
63                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
64                 
65                 } else {
66                 
67                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
68                 
69                 }
70                 
71                 // Add to form.
72                 
73                 wxListItem coldata;
74                 
75                 coldata.SetId(CategoryListIndex);
76                 coldata.SetData(CategoryListIndex);
77                 coldata.SetText(txtCategory->GetValue());
78                 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
79                 
80                 if (chkUsePref->IsChecked()){
81                 
82                         CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
83                 
84                 }
85                 
86                 this->Close();
87                 
88         } else if (EditorMode == TRUE) {
89         
90                 long longSelected = -1;
91                 wxString strValue;      
92         
93                 // Update Category Name.
94                 
95                 CategoryListPtr->erase(CategoryListIndex);
96                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
97                 
98                 // Update Category Type.
99                 
100                 CategoryListTypePtr->erase(CategoryListIndex);
101         
102                 strValue = cmbType->GetString(cmbType->GetSelection());
103                 
104                 if (strValue == _("Home")) {
105                 
106                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
107                 
108                 } else if (strValue == _("Work")) {
109                 
110                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
111                 
112                 }               
113                 
114                 // Update Category Priority.
115                 
116                 CategoryListPrefPtr->erase(CategoryListIndex);
117                 
118                 if (chkUsePref->IsChecked()){
119                 
120                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, sliPriority->GetValue()));
121                 
122                 } else {
123                 
124                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
125                 
126                 }
127                 
128                 // Update form.
129                 
130                 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, 
131                         wxLIST_NEXT_ALL,
132                         wxLIST_STATE_SELECTED);
133                         
134                 if (longSelected == -1){
135                         return;
136                 }               
137                 
138                 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
139                 
140                 if (chkUsePref->IsChecked()){
141                 
142                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
143                 
144                 } else {
145                 
146                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
147                 
148                 }
149                 
150                 this->Close();  
151         
152         }
156 void frmContactEditorCategory::SetEditorMode(bool EditMode)
158         // Set if the editor is adding or editing an address.
159         // FALSE = Add
160         // TRUE = Edit
161         
162         if (EditMode == FALSE){
163         
164                 EditorMode = FALSE;
165                 btnAction->SetLabel(_("Add"));
166                 this->SetTitle(_("Add Category"));
167         
168         } else if (EditMode == TRUE){
169         
170                 EditorMode = TRUE;
171                 btnAction->SetLabel(_("Modify"));
172                 this->SetTitle(_("Modify Category"));           
173                 
174                 // Load the data into the form.
175                 
176                 std::map<int,int>::iterator intiter;
177                 std::map<int,wxString>::iterator striter;               
178                 wxString strValue;              
179                         
180                 // Get the organisation name.
181                 
182                 striter = CategoryListPtr->find(CategoryListIndex);
183                  
184                 if (striter->first == CategoryListIndex){
185                 
186                         strValue = striter->second;
187                 
188                 }
189                 
190                 txtCategory->SetValue(strValue);
191                 
192                 strValue.Clear();
193                 
194                 // Get the type.
195                 
196                 striter = CategoryListTypePtr->find(CategoryListIndex); 
197                 
198                 if (striter->first == CategoryListIndex){
199                 
200                         strValue = striter->second;
201                 
202                 }
203                 
204                 if (strValue == wxT("home")){
205                 
206                         cmbType->SetSelection(1);
207                 
208                 } else if (strValue == wxT("work")){
209                 
210                         cmbType->SetSelection(2);       
211                 
212                 } else {
213                 
214                         cmbType->SetSelection(0);
215                 
216                 }
217                 
218                 // Get the organisation priority.
219                 
220                 intiter = CategoryListPrefPtr->find(CategoryListIndex);
221                 
222                 if (intiter->first == CategoryListIndex && intiter->second > 0){
223                 
224                         sliPriority->SetValue(intiter->second);
225                         sliPriority->Enable();
226                         chkUsePref->SetValue(TRUE);
227                 
228                 }
229                 
230         }
231                 
234 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
236         this->Close();
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,
246         int CategoryIndex )
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;
258         
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