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);
37 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
40 // Set the editor mode for adding or editing an email address.
42 if (EditMode == FALSE){
45 btnAction->SetLabel(_("Add"));
46 this->SetTitle(_("Add Language"));
48 } else if (EditMode == TRUE){
51 btnAction->SetLabel(_("Modify"));
52 this->SetTitle(_("Modify Language"));
54 std::map<int,int>::iterator intiter;
55 std::map<int,wxString>::iterator striter;
58 // Load the data into the form.
60 striter = LanguageListPtr->find(LanguageListIndex);
62 if (striter->first == LanguageListIndex){
64 strValue = striter->second;
68 txtLanguage->SetValue(strValue);
72 intiter = LanguageListPrefPtr->find(LanguageListIndex);
74 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
75 intiter != LanguageListPrefPtr->end()){
77 priorityCtrl->SetValue(intiter->second);
78 priorityCtrl->EnablePriority(true);
84 EditSectionType = SectType;
87 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
90 // Process the action.
94 if (EditorMode == FALSE){
96 // Add the language to the list.
102 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
106 if (EditSectionType == CE_GENERAL){
108 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
110 } else if (EditSectionType == CE_HOME) {
112 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
114 } else if (EditSectionType == CE_WORK) {
116 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
120 // Add Language priority.
122 if (priorityCtrl->IsPriorityChecked()){
124 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
128 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
132 // Add the data to the form.
136 coldata.SetId(LanguageListIndex);
137 coldata.SetData(LanguageListIndex);
138 coldata.SetText(txtLanguage->GetValue());
139 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
141 if (priorityCtrl->IsPriorityChecked()){
143 LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
149 } else if (EditorMode == TRUE){
151 // Edit the language.
155 long longSelected = -1;
157 LanguageListPtr->erase(LanguageListIndex);
158 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
160 LanguageListPrefPtr->erase(LanguageListIndex);
162 if (priorityCtrl->IsPriorityChecked()){
164 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
168 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
172 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected,
174 wxLIST_STATE_SELECTED);
176 if (longSelected == -1){
180 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());
182 if (priorityCtrl->IsPriorityChecked()){
184 LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
188 LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
198 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
207 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
208 std::map<int, wxString> *LanguageListAltID,
209 std::map<int, wxString> *LanguageListPID,
210 std::map<int, wxString> *LanguageListType,
211 std::map<int, wxString> *LanguageListTokens,
212 std::map<int, int> *LanguageListPref,
213 wxListCtrl *LanguageListCtrl,
217 // Setup the pointers so that the data can be processed without
220 LanguageListPtr = LanguageList;
221 LanguageListAltIDPtr = LanguageListAltID;
222 LanguageListPIDPtr = LanguageListPID;
223 LanguageListTypePtr = LanguageListType;
224 LanguageListTokensPtr = LanguageListTokens;
225 LanguageListPrefPtr = LanguageListPref;
226 LanguageListCtrlPtr = LanguageListCtrl;
227 LanguageListIndex = LanguageIndex;