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);
31 szrPriority->Layout();
33 // Setup the language combo box.
35 std::vector<std::string> LanguageCodeList = GetLanguageCodeList();
37 wxArrayString LanguageList;
39 for (auto LanguageItem : LanguageCodeList){
41 LanguageList.Add((wxString)LanguageItem, 1);
45 cmbLanguage->Append(LanguageList);
49 void frmContactEditorNotes::ProcessAction( wxCommandEvent& event )
56 if (EditorMode == FALSE){
58 // Add the note to the list.
65 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
69 if (EditSectionType == CE_GENERAL){
71 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("")));
73 } else if (EditSectionType == CE_HOME) {
75 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("home")));
77 } else if (EditSectionType == CE_WORK) {
79 NotesListTypePtr->insert(std::make_pair(NotesListIndex, wxT("work")));
85 if (priorityCtrl->IsPriorityChecked()){
87 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
91 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
99 if (!strValue.IsEmpty()){
101 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
105 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
109 // Add the data to the form.
113 coldata.SetId(NotesListIndex);
114 coldata.SetData(NotesListIndex);
115 coldata.SetText(txtNote->GetValue());
116 ListCtrlIndex = NotesListCtrlPtr->InsertItem(coldata);
118 if (priorityCtrl->IsPriorityChecked()){
120 NotesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
126 } else if (EditorMode == TRUE){
132 long longSelected = -1;
136 NotesListPtr->erase(NotesListIndex);
137 NotesListPtr->insert(std::make_pair(NotesListIndex, txtNote->GetValue()));
139 // Update the note preference.
141 NotesListPrefPtr->erase(NotesListIndex);
143 if (priorityCtrl->IsPriorityChecked()){
145 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, priorityCtrl->GetValue()));
149 NotesListPrefPtr->insert(std::make_pair(NotesListIndex, 0));
153 // Update the language.
157 NotesListLangPtr->erase(NotesListIndex);
159 if (!strValue.IsEmpty()){
161 NotesListLangPtr->insert(std::make_pair(NotesListIndex, cmbLanguage->GetValue()));
165 NotesListLangPtr->insert(std::make_pair(NotesListIndex, wxT("")));
171 longSelected = NotesListCtrlPtr->GetNextItem(longSelected,
173 wxLIST_STATE_SELECTED);
175 if (longSelected == -1){
179 NotesListCtrlPtr->SetItem(longSelected, 0, txtNote->GetValue());
181 if (priorityCtrl->IsPriorityChecked()){
183 NotesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
187 NotesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
197 void frmContactEditorNotes::SetEditorMode(bool EditMode, SectionType SectType)
200 // Set the editor mode.
202 // Set if the editor is adding or editing an address.
206 if (EditMode == FALSE){
209 btnAction->SetLabel(_("Add"));
210 this->SetTitle(_("Add Note"));
212 } else if (EditMode == TRUE){
215 btnAction->SetLabel(_("Modify"));
216 this->SetTitle(_("Modify Note"));
218 std::map<int,int>::iterator intiter;
219 std::map<int,wxString>::iterator striter;
224 striter = NotesListPtr->find(NotesListIndex);
226 if (striter->first == NotesListIndex){
228 strValue = striter->second;
232 txtNote->SetValue(strValue);
236 striter = NotesListLangPtr->find(NotesListIndex);
240 if (striter->first == NotesListIndex &&
241 striter != NotesListLangPtr->end()){
243 strValue = striter->second;
247 cmbLanguage->SetValue(strValue);
251 intiter = NotesListPrefPtr->find(NotesListIndex);
253 if (intiter->first == NotesListIndex && intiter->second > 0 &&
254 intiter != NotesListPrefPtr->end()){
256 priorityCtrl->SetValue(intiter->second);
257 priorityCtrl->EnablePriority(true);
263 EditSectionType = SectType;
267 void frmContactEditorNotes::CloseWindow( wxCommandEvent& event )
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,
288 // Setup the pointers.
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;