1 #include "frmContactEditorNotes.h"
2 #include "../common/textprocessing.h"
3 #include <wx/tokenzr.h>
5 frmContactEditorNotes::frmContactEditorNotes( wxWindow* parent )
7 frmContactEditorNotesADT( parent )
10 sliPriority->Disable();
13 void frmContactEditorNotes::EnablePriority( wxCommandEvent& event )
15 if (chkUsePref->IsChecked()){
16 sliPriority->Enable();
18 sliPriority->Disable();
22 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
26 if (EditorMode == FALSE){
28 // Add the note to the list.
35 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
39 if (EditSectionType == CE_GENERAL){
41 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
43 } else if (EditSectionType == CE_HOME) {
45 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
47 } else if (EditSectionType == CE_WORK) {
49 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
55 if (chkUsePref->IsChecked()){
57 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
61 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
69 if (!strValue.IsEmpty()){
71 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
75 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
79 // Add the data to the form.
83 coldata.SetId(NotesListIndex);
84 coldata.SetData(NotesListIndex);
85 coldata.SetText(txtNote->GetValue());
86 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
88 if (chkUsePref->IsChecked()){
90 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
96 } else if (EditorMode == TRUE){
102 long longSelected = -1;
106 NotesListPtr->erase(NotesListIndex);
107 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
109 // Update the note preference.
111 NotesListPrefPtr->erase(NotesListIndex);
113 if (chkUsePref->IsChecked()){
115 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, sliPriority->GetValue()));
119 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
123 // Update the language.
127 NotesListLangPtr->erase(NotesListIndex);
129 if (!strValue.IsEmpty()){
131 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
135 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
141 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
143 wxLIST_STATE_SELECTED);
145 if (longSelected == -1){
149 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
151 if (chkUsePref->IsChecked()){
153 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
157 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
167 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
169 // Set if the editor is adding or editing an address.
173 if (EditMode == FALSE){
176 btnAction->SetLabel(_("Add"));
177 this->SetTitle(_("Add Note"));
179 } else if (EditMode == TRUE){
182 btnAction->SetLabel(_("Modify"));
183 this->SetTitle(_("Modify Note"));
185 std::map<int,int>::iterator intiter;
186 std::map<int,wxString>::iterator striter;
191 striter = NotesListPtr->find(NotesListIndex);
193 if (striter->first == NotesListIndex){
195 strValue = striter->second;
199 txtNote->SetValue(strValue);
203 striter = NotesListLangPtr->find(NotesListIndex);
205 if (striter->first == NotesListIndex){
207 strValue = striter->second;
211 cmbLanguage->SetValue(strValue);
215 intiter = NotesListPrefPtr->find(NotesListIndex);
217 if (intiter->first == NotesListIndex && intiter->second > 0){
219 sliPriority->SetValue(intiter->second);
220 sliPriority->Enable();
221 chkUsePref->SetValue(TRUE);
227 EditSectionType = SectType;
231 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
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,
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;