1 // frmContactEditorNotes.cpp - frmContactEditorNotes form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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 )
23 frmContactEditorNotesADT( parent )
26 // Setup the editor window.
29 priorityCtrl = new XABPriorityCtrl(tabPriority);
30 szrPriority->Add(priorityCtrl, 1, wxEXPAND, 5);
32 // Setup the language combo box.
34 std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
36 wxArrayString LanguageList;
38 for (auto LanguageItem : LanguageCodeList){
40 LanguageList.Add((wxString)LanguageItem, 1);
44 cmbLanguage->Append(LanguageList);
48 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
55 if (EditorMode == FALSE){
57 // Add the note to the list.
64 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
68 if (EditSectionType == CE_GENERAL){
70 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
72 } else if (EditSectionType == CE_HOME) {
74 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
76 } else if (EditSectionType == CE_WORK) {
78 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
84 if (priorityCtrl->IsPriorityChecked()){
86 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
90 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
98 if (!strValue.IsEmpty()){
100 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
104 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
108 // Add the data to the form.
112 coldata.SetId(NotesListIndex);
113 coldata.SetData(NotesListIndex);
114 coldata.SetText(txtNote->GetValue());
115 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
117 if (priorityCtrl->IsPriorityChecked()){
119 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
125 } else if (EditorMode == TRUE){
131 long longSelected = -1;
135 NotesListPtr->erase(NotesListIndex);
136 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
138 // Update the note preference.
140 NotesListPrefPtr->erase(NotesListIndex);
142 if (priorityCtrl->IsPriorityChecked()){
144 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
148 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
152 // Update the language.
156 NotesListLangPtr->erase(NotesListIndex);
158 if (!strValue.IsEmpty()){
160 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
164 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
170 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
172 wxLIST_STATE_SELECTED);
174 if (longSelected == -1){
178 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
180 if (priorityCtrl->IsPriorityChecked()){
182 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
186 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
196 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
199 // Set the editor mode.
201 // Set if the editor is adding or editing an address.
205 if (EditMode == FALSE){
208 btnAction->SetLabel(_("Add"));
209 this->SetTitle(_("Add Note"));
211 } else if (EditMode == TRUE){
214 btnAction->SetLabel(_("Modify"));
215 this->SetTitle(_("Modify Note"));
217 std::map<int,int>::iterator intiter;
218 std::map<int,wxString>::iterator striter;
223 striter = NotesListPtr->find(NotesListIndex);
225 if (striter->first == NotesListIndex){
227 strValue = striter->second;
231 txtNote->SetValue(strValue);
235 striter = NotesListLangPtr->find(NotesListIndex);
239 if (striter->first == NotesListIndex &&
240 striter != NotesListLangPtr->end()){
242 strValue = striter->second;
246 cmbLanguage->SetValue(strValue);
250 intiter = NotesListPrefPtr->find(NotesListIndex);
252 if (intiter->first == NotesListIndex && intiter->second > 0 &&
253 intiter != NotesListPrefPtr->end()){
255 priorityCtrl->SetValue(intiter->second);
256 priorityCtrl->EnablePriority(true);
262 EditSectionType = SectType;
266 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
276 void frmContactEditorNotes::SetupPointers(std::map<int, wxString> *NotesList,
277 std::map<int, wxString> *NotesListLang,
278 std::map<int, wxString> *NotesListAltID,
279 std::map<int, wxString> *NotesListPID,
280 std::map<int, wxString> *NotesListType,
281 std::map<int, wxString> *NotesListTokens,
282 std::map<int, int> *NotesListPref,
283 wxListCtrl *NotesListCtrl,
287 // Setup the pointers.
289 NotesListPtr = NotesList;
290 NotesListLangPtr = NotesListLang;
291 NotesListAltIDPtr = NotesListAltID;
292 NotesListPIDPtr = NotesListPID;
293 NotesListTypePtr = NotesListType;
294 NotesListTokensPtr = NotesListTokens;
295 NotesListPrefPtr = NotesListPref;
296 NotesListCtrlPtr = NotesListCtrl;
297 NotesListIndex = NotesIndex;