Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorNotes.cpp
1 // frmContactEditorNotes.cpp - frmContactEditorNotes 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 "frmContactEditorNotes.h"
21 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
22 :
23 frmContactEditorNotesADT( parent )
24 {
25         
26         // Setup the editor window.
27         
28         EditorMode = FALSE;
29         priorityCtrl = new XABPriorityCtrl(tabPriority);
30         szrPriority->Add(priorityCtrl, 1, wxEXPAND, 5);
31         szrPriority->Layout();
32         
33         // Setup the language combo box.
34         
35         std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
36         
37         wxArrayString LanguageList;
38         
39         for (auto LanguageItem : LanguageCodeList){
40                 
41                 LanguageList.Add((wxString)LanguageItem, 1);
42                 
43         }
44         
45         cmbLanguage->Append(LanguageList);
46         
47 }
49 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
50 {
51         
52         // Process action.
53         
54         long ListCtrlIndex;
55         
56         if (EditorMode == FALSE){
57         
58                 // Add the note to the list.
59         
60                 wxString strAddress;
61                 wxString strValue;
62                 
63                 // Add note.
64                 
65                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
66                 
67                 // Add note type.
68                 
69                 if (EditSectionType == CE_GENERAL){
70                 
71                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
72                 
73                 } else if (EditSectionType == CE_HOME) {
74                 
75                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
76                 
77                 } else if (EditSectionType == CE_WORK) {
78                 
79                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
80                 
81                 }
82                 
83                 // Add note priority.
84                 
85                 if (priorityCtrl->IsPriorityChecked()){
86                 
87                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
88                 
89                 } else {
90                 
91                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
92                 
93                 }               
94                 
95                 // Add note language.
96                 
97                 strValue.Clear();
98                 
99                 if (!strValue.IsEmpty()){
100                 
101                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
102                 
103                 } else {
104                 
105                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
106                 
107                 }
108                 
109                 // Add the data to the form.
110                 
111                 wxListItem coldata;
112                 
113                 coldata.SetId(NotesListIndex);
114                 coldata.SetData(NotesListIndex);                
115                 coldata.SetText(txtNote->GetValue());
116                 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
117                 
118                 if (priorityCtrl->IsPriorityChecked()){
119                 
120                         NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
121                 
122                 }
123                 
124                 this->Close();
125         
126         } else if (EditorMode == TRUE){
127         
128                 // Edit the note.
129                 
130                 wxString strAddress;
131                 wxString strValue;
132                 long longSelected = -1;
134                 // Update the note.
136                 NotesListPtr->erase(NotesListIndex);
137                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
138                 
139                 // Update the note preference.
140                 
141                 NotesListPrefPtr->erase(NotesListIndex);
142                 
143                 if (priorityCtrl->IsPriorityChecked()){
144                 
145                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
146                 
147                 } else {
148                 
149                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
150                 
151                 }
152                 
153                 // Update the language.
154                 
155                 strValue.Clear();
156                 
157                 NotesListLangPtr->erase(NotesListIndex);
158                 
159                 if (!strValue.IsEmpty()){
160                 
161                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
162                 
163                 } else {
164                 
165                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
166                 
167                 }               
168                 
169                 // Update the form.
170                 
171                 longSelected = NotesListCtrlPtr->GetNextItem(longSelected, 
172                         wxLIST_NEXT_ALL,
173                         wxLIST_STATE_SELECTED);
174                         
175                 if (longSelected == -1){
176                         return;
177                 }
178                 
179                 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
180                 
181                 if (priorityCtrl->IsPriorityChecked()){
182                 
183                         NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
184                 
185                 } else {
186                 
187                         NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
188                 
189                 }       
190                         
191                 this->Close();  
192         
193         }       
194         
197 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
199         
200         // Set the editor mode.
201         
202         // Set if the editor is adding or editing an address.
203         // FALSE = Add
204         // TRUE = Edit
205         
206         if (EditMode == FALSE){
207         
208                 EditorMode = FALSE;
209                 btnAction->SetLabel(_("Add"));
210                 this->SetTitle(_("Add Note"));
211         
212         } else if (EditMode == TRUE){
213         
214                 EditorMode = TRUE;
215                 btnAction->SetLabel(_("Modify"));
216                 this->SetTitle(_("Modify Note"));
217                 
218                 std::map<int,int>::iterator intiter;
219                 std::map<int,wxString>::iterator striter;               
220                 wxString strValue;              
221                 
222                 // Get the note.
223                 
224                 striter = NotesListPtr->find(NotesListIndex);
225                  
226                 if (striter->first == NotesListIndex){
227                 
228                         strValue = striter->second;
229                 
230                 }
231                 
232                 txtNote->SetValue(strValue);
233                 
234                 // Get the language.
235                 
236                 striter = NotesListLangPtr->find(NotesListIndex);
237                 
238                 strValue.clear();
239                 
240                 if (striter->first == NotesListIndex &&
241                         striter != NotesListLangPtr->end()){
242                 
243                         strValue = striter->second;
244                 
245                 }
246                 
247                 cmbLanguage->SetValue(strValue);
248                 
249                 // Get the priority.
250                 
251                 intiter = NotesListPrefPtr->find(NotesListIndex);
252                 
253                 if (intiter->first == NotesListIndex && intiter->second > 0 &&
254                         intiter != NotesListPrefPtr->end()){
255                 
256                         priorityCtrl->SetValue(intiter->second);
257                         priorityCtrl->EnablePriority(true);
258                 
259                 }
260                 
261         }
262         
263         EditSectionType = SectType;     
264                 
267 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
269         
270         // Close the window.
271         
272         this->Close();
273         
277 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
278         std::map<int, wxString> *NotesListLang,
279         std::map<int, wxString> *NotesListAltID,
280         std::map<int, wxString> *NotesListPID,
281         std::map<int, wxString> *NotesListType,
282         std::map<int, wxString> *NotesListTokens,
283         std::map<int, int> *NotesListPref,
284         wxListCtrl *NotesListCtrl,
285         int NotesIndex )
288         // Setup the pointers.
289         
290         NotesListPtr = NotesList;
291         NotesListLangPtr = NotesListLang;
292         NotesListAltIDPtr = NotesListAltID;
293         NotesListPIDPtr = NotesListPID;
294         NotesListTypePtr = NotesListType;
295         NotesListTokensPtr = NotesListTokens;
296         NotesListPrefPtr = NotesListPref;
297         NotesListCtrlPtr = NotesListCtrl;
298         NotesListIndex = NotesIndex;
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