Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Initial import of code already done for Xestia Address Book
[xestiaab/.git] / source / contacteditor / frmContactEditorNotes.cpp
1 #include "frmContactEditorNotes.h"
2 #include "../common/textprocessing.h"
3 #include <wx/tokenzr.h>
5 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
6 :
7 frmContactEditorNotesADT( parent )
8 {
9         EditorMode = FALSE;
10         sliPriority->Disable();
11 }
13 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
14 {
15         if (chkUsePref->IsChecked()){
16                 sliPriority->Enable();
17         } else {
18                 sliPriority->Disable();
19         }
20 }
22 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
23 {
24         long ListCtrlIndex;
25         
26         if (EditorMode == FALSE){
27         
28                 // Add the note to the list.
29         
30                 wxString strAddress;
31                 wxString strValue;
32                 
33                 // Add note.
34                 
35                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
36                 
37                 // Add note type.
38                 
39                 if (EditSectionType == CE_GENERAL){
40                 
41                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
42                 
43                 } else if (EditSectionType == CE_HOME) {
44                 
45                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
46                 
47                 } else if (EditSectionType == CE_WORK) {
48                 
49                         NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
50                 
51                 }
52                 
53                 // Add note priority.
54                 
55                 if (chkUsePref->IsChecked()){
56                 
57                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
58                 
59                 } else {
60                 
61                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
62                 
63                 }               
64                 
65                 // Add note language.
66                 
67                 strValue.Clear();
68                 
69                 if (!strValue.IsEmpty()){
70                 
71                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
72                 
73                 } else {
74                 
75                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
76                 
77                 }
78                 
79                 // Add the data to the form.
80                 
81                 wxListItem coldata;
82                 
83                 coldata.SetId(NotesListIndex);
84                 coldata.SetData(NotesListIndex);                
85                 coldata.SetText(txtNote->GetValue());
86                 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
87                 
88                 if (chkUsePref->IsChecked()){
89                 
90                         NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
91                 
92                 }
93                 
94                 this->Close();
95         
96         } else if (EditorMode == TRUE){
97         
98                 // Edit the note.
99                 
100                 wxString strAddress;
101                 wxString strValue;
102                 long longSelected = -1;
104                 // Update the note.
106                 NotesListPtr->erase(NotesListIndex);
107                 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
108                 
109                 // Update the note preference.
110                 
111                 NotesListPrefPtr->erase(NotesListIndex);
112                 
113                 if (chkUsePref->IsChecked()){
114                 
115                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
116                 
117                 } else {
118                 
119                         NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));            
120                 
121                 }
122                 
123                 // Update the language.
124                 
125                 strValue.Clear();
126                 
127                 NotesListLangPtr->erase(NotesListIndex);
128                 
129                 if (!strValue.IsEmpty()){
130                 
131                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));              
132                 
133                 } else {
134                 
135                         NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
136                 
137                 }               
138                 
139                 // Update the form.
140                 
141                 longSelected = NotesListCtrlPtr->GetNextItem(longSelected, 
142                         wxLIST_NEXT_ALL,
143                         wxLIST_STATE_SELECTED);
144                         
145                 if (longSelected == -1){
146                         return;
147                 }
148                 
149                 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
150                 
151                 if (chkUsePref->IsChecked()){
152                 
153                         NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
154                 
155                 } else {
156                 
157                         NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
158                 
159                 }       
160                         
161                 this->Close();  
162         
163         }       
164         
167 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
169         // Set if the editor is adding or editing an address.
170         // FALSE = Add
171         // TRUE = Edit
172         
173         if (EditMode == FALSE){
174         
175                 EditorMode = FALSE;
176                 btnAction->SetLabel(_("Add"));
177                 this->SetTitle(_("Add Note"));
178         
179         } else if (EditMode == TRUE){
180         
181                 EditorMode = TRUE;
182                 btnAction->SetLabel(_("Modify"));
183                 this->SetTitle(_("Modify Note"));
184                 
185                 std::map<int,int>::iterator intiter;
186                 std::map<int,wxString>::iterator striter;               
187                 wxString strValue;              
188                 
189                 // Get the note.
190                 
191                 striter = NotesListPtr->find(NotesListIndex);
192                  
193                 if (striter->first == NotesListIndex){
194                 
195                         strValue = striter->second;
196                 
197                 }
198                 
199                 txtNote->SetValue(strValue);
200                 
201                 // Get the language.
202                 
203                 striter = NotesListLangPtr->find(NotesListIndex);
204                 
205                 if (striter->first == NotesListIndex){
206                 
207                         strValue = striter->second;
208                 
209                 }
210                 
211                 cmbLanguage->SetValue(strValue);
212                 
213                 // Get the priority.
214                 
215                 intiter = NotesListPrefPtr->find(NotesListIndex);
216                 
217                 if (intiter->first == NotesListIndex && intiter->second > 0){
218                 
219                         sliPriority->SetValue(intiter->second);
220                         sliPriority->Enable();
221                         chkUsePref->SetValue(TRUE);
222                 
223                 }
224                 
225         }
226         
227         EditSectionType = SectType;     
228                 
231 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
233         this->Close();
237 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
238         std::map<int, wxString> *NotesListLang,
239         std::map<int, wxString> *NotesListAltID,
240         std::map<int, wxString> *NotesListPID,
241         std::map<int, wxString> *NotesListType,
242         std::map<int, wxString> *NotesListTokens,
243         std::map<int, int> *NotesListPref,
244         wxListCtrl *NotesListCtrl,
245         int NotesIndex )
248         NotesListPtr = NotesList;
249         NotesListLangPtr = NotesListLang;
250         NotesListAltIDPtr = NotesListAltID;
251         NotesListPIDPtr = NotesListPID;
252         NotesListTypePtr = NotesListType;
253         NotesListTokensPtr = NotesListTokens;
254         NotesListPrefPtr = NotesListPref;
255         NotesListCtrlPtr = NotesListCtrl;
256         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