Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorCategory.cpp
1 // frmContactEditorCategory.cpp - frmContactEditorCategory 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 "frmContactEditorCategory.h"
20 #include <wx/tokenzr.h>
21 #include "../common/textprocessing.h"
23 frmContactEditorCategory::frmContactEditorCategory( wxWindow* parent )
24 :
25 frmContactEditorCategoryADT( 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();
35         cmbType->Append(wxT(""));
36         cmbType->Append(_("Home"));
37         cmbType->Append(_("Work"));     
38 }
40 void frmContactEditorCategory::ProcessAction( wxCommandEvent& event )
41 {
43         // Process action.
44         
45         long ListCtrlIndex;
46         
47         if (EditorMode == FALSE){
49                 wxString strValue;
50         
51                 // Setup Organisation Name.
52                 
53                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
55                 strValue.Clear();
57                 strValue = cmbType->GetString(cmbType->GetSelection());
59                 // Setup Category Type.
61                 if (strValue == _("Home")) {
62                 
63                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
64                 
65                 } else if (strValue == _("Work")) {
66                 
67                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
68                 
69                 } else {
70                 
71                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("")));
72                 
73                 }
74                 
75                 // Setup Category Priority.
76                 
77                 if (priorityCtrl->IsPriorityChecked()){
78                 
79                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
80                 
81                 } else {
82                 
83                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
84                 
85                 }
86                 
87                 // Add to form.
88                 
89                 wxListItem coldata;
90                 
91                 coldata.SetId(CategoryListIndex);
92                 coldata.SetData(CategoryListIndex);
93                 coldata.SetText(txtCategory->GetValue());
94                 ListCtrlIndex = CategoryListCtrlPtr->InsertItem(coldata);
95                 
96                 if (priorityCtrl->IsPriorityChecked()){
97                 
98                         CategoryListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
99                 
100                 }
101                 
102                 this->Close();
103                 
104         } else if (EditorMode == TRUE) {
105         
106                 long longSelected = -1;
107                 wxString strValue;      
108         
109                 // Update Category Name.
110                 
111                 CategoryListPtr->erase(CategoryListIndex);
112                 CategoryListPtr->insert(std::make_pair(CategoryListIndex, txtCategory->GetValue()));
113                 
114                 // Update Category Type.
115                 
116                 CategoryListTypePtr->erase(CategoryListIndex);
117         
118                 strValue = cmbType->GetString(cmbType->GetSelection());
119                 
120                 if (strValue == _("Home")) {
121                 
122                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("home")));
123                 
124                 } else if (strValue == _("Work")) {
125                 
126                         CategoryListTypePtr->insert(std::make_pair(CategoryListIndex, wxT("work")));
127                 
128                 }               
129                 
130                 // Update Category Priority.
131                 
132                 CategoryListPrefPtr->erase(CategoryListIndex);
133                 
134                 if (priorityCtrl->IsPriorityChecked()){
135                 
136                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, priorityCtrl->GetValue()));
137                 
138                 } else {
139                 
140                         CategoryListPrefPtr->insert(std::make_pair(CategoryListIndex, 0));
141                 
142                 }
143                 
144                 // Update form.
145                 
146                 longSelected = CategoryListCtrlPtr->GetNextItem(longSelected, 
147                         wxLIST_NEXT_ALL,
148                         wxLIST_STATE_SELECTED);
149                         
150                 if (longSelected == -1){
151                         return;
152                 }               
153                 
154                 CategoryListCtrlPtr->SetItem(longSelected, 0, txtCategory->GetValue());
155                 
156                 if (priorityCtrl->IsPriorityChecked()){
157                 
158                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
159                 
160                 } else {
161                 
162                         CategoryListCtrlPtr->SetItem(longSelected, 1, wxT(""));
163                 
164                 }
165                 
166                 this->Close();  
167         
168         }
172 void frmContactEditorCategory::SetEditorMode(bool EditMode)
174         
175         // Set the editor mode.
176         
177         // Set if the editor is adding or editing an address.
178         // FALSE = Add
179         // TRUE = Edit
180         
181         if (EditMode == FALSE){
182         
183                 EditorMode = FALSE;
184                 btnAction->SetLabel(_("Add"));
185                 this->SetTitle(_("Add Category"));
186         
187         } else if (EditMode == TRUE){
188         
189                 EditorMode = TRUE;
190                 btnAction->SetLabel(_("Modify"));
191                 this->SetTitle(_("Modify Category"));           
192                 
193                 // Load the data into the form.
194                 
195                 std::map<int,int>::iterator intiter;
196                 std::map<int,wxString>::iterator striter;               
197                 wxString strValue;              
198                         
199                 // Get the organisation name.
200                 
201                 striter = CategoryListPtr->find(CategoryListIndex);
202                  
203                 if (striter->first == CategoryListIndex){
204                 
205                         strValue = striter->second;
206                 
207                 }
208                 
209                 txtCategory->SetValue(strValue);
210                 
211                 strValue.Clear();
212                 
213                 // Get the type.
214                 
215                 striter = CategoryListTypePtr->find(CategoryListIndex); 
216                 
217                 if (striter->first == CategoryListIndex &&
218                         striter != CategoryListTypePtr->end()){
219                 
220                         strValue = striter->second;
221                 
222                 }
223                 
224                 if (strValue == wxT("home")){
225                 
226                         cmbType->SetSelection(1);
227                 
228                 } else if (strValue == wxT("work")){
229                 
230                         cmbType->SetSelection(2);       
231                 
232                 } else {
233                 
234                         cmbType->SetSelection(0);
235                 
236                 }
237                 
238                 // Get the organisation priority.
239                 
240                 intiter = CategoryListPrefPtr->find(CategoryListIndex);
241                 
242                 if (intiter->first == CategoryListIndex && intiter->second > 0 &&
243                         intiter != CategoryListPrefPtr->end()){
244                 
245                         priorityCtrl->SetValue(intiter->second);
246                         priorityCtrl->EnablePriority(true);
247                 
248                 }
249                 
250         }
251                 
254 void frmContactEditorCategory::CloseWindow( wxCommandEvent& event )
256         
257         // Close this window.
258         
259         this->Close();
260         
263 void frmContactEditorCategory::SetupPointers(std::map<int, wxString> *CategoryList,
264         std::map<int, wxString> *CategoryListAltID,
265         std::map<int, wxString> *CategoryListPID,
266         std::map<int, wxString> *CategoryListType,
267         std::map<int, wxString> *CategoryListTokens,
268         std::map<int, int> *CategoryListPref,
269         wxListCtrl *CategoryListCtrl,
270         int CategoryIndex )
273         // Setup the pointers.
274         
275         CategoryListPtr = CategoryList;
276         CategoryListAltIDPtr = CategoryListAltID;
277         CategoryListPIDPtr = CategoryListPID;
278         CategoryListTypePtr = CategoryListType;
279         CategoryListTokensPtr = CategoryListTokens;
280         CategoryListPrefPtr = CategoryListPref;
281         CategoryListCtrlPtr = CategoryListCtrl;
282         CategoryListIndex = CategoryIndex;
283         
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