1 // frmContactEditorLanguages.cpp - frmContactEditorLanguages 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 "frmContactEditorLanguages.h"
20 #include "../common/textprocessing.h"
23 frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent )
25 frmContactEditorLanguagesADT( parent )
31 priorityCtrl = new XABPriorityCtrl(tabGeneral);
32 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
36 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
39 // Set the editor mode for adding or editing an email address.
41 if (EditMode == FALSE){
44 btnAction->SetLabel(_("Add"));
45 this->SetTitle(_("Add Language"));
47 } else if (EditMode == TRUE){
50 btnAction->SetLabel(_("Modify"));
51 this->SetTitle(_("Modify Language"));
53 std::map<int,int>::iterator intiter;
54 std::map<int,wxString>::iterator striter;
57 // Load the data into the form.
59 striter = LanguageListPtr->find(LanguageListIndex);
61 if (striter->first == LanguageListIndex){
63 strValue = striter->second;
67 txtLanguage->SetValue(strValue);
71 intiter = LanguageListPrefPtr->find(LanguageListIndex);
73 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
74 intiter != LanguageListPrefPtr->end()){
76 priorityCtrl->SetValue(intiter->second);
77 priorityCtrl->EnablePriority(true);
83 EditSectionType = SectType;
86 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
89 // Process the action.
93 if (EditorMode == FALSE){
95 // Add the language to the list.
101 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
105 if (EditSectionType == CE_GENERAL){
107 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
109 } else if (EditSectionType == CE_HOME) {
111 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
113 } else if (EditSectionType == CE_WORK) {
115 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
119 // Add Language priority.
121 if (priorityCtrl->IsPriorityChecked()){
123 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
127 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
131 // Add the data to the form.
135 coldata.SetId(LanguageListIndex);
136 coldata.SetData(LanguageListIndex);
137 coldata.SetText(txtLanguage->GetValue());
138 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
140 if (priorityCtrl->IsPriorityChecked()){
142 LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
148 } else if (EditorMode == TRUE){
150 // Edit the language.
154 long longSelected = -1;
156 LanguageListPtr->erase(LanguageListIndex);
157 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
159 LanguageListPrefPtr->erase(LanguageListIndex);
161 if (priorityCtrl->IsPriorityChecked()){
163 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
167 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
171 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected,
173 wxLIST_STATE_SELECTED);
175 if (longSelected == -1){
179 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());
181 if (priorityCtrl->IsPriorityChecked()){
183 LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
187 LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
197 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
206 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
207 std::map<int, wxString> *LanguageListAltID,
208 std::map<int, wxString> *LanguageListPID,
209 std::map<int, wxString> *LanguageListType,
210 std::map<int, wxString> *LanguageListTokens,
211 std::map<int, int> *LanguageListPref,
212 wxListCtrl *LanguageListCtrl,
216 // Setup the pointers so that the data can be processed without
219 LanguageListPtr = LanguageList;
220 LanguageListAltIDPtr = LanguageListAltID;
221 LanguageListPIDPtr = LanguageListPID;
222 LanguageListTypePtr = LanguageListType;
223 LanguageListTokensPtr = LanguageListTokens;
224 LanguageListPrefPtr = LanguageListPref;
225 LanguageListCtrlPtr = LanguageListCtrl;
226 LanguageListIndex = LanguageIndex;