1 #include "frmContactEditorLanguages.h"
2 #include "../common/textprocessing.h"
5 frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent )
7 frmContactEditorLanguagesADT( parent )
10 sliPriority->Disable();
13 void frmContactEditorLanguages::EnablePriority( wxCommandEvent& event )
15 if (chkUsePref->IsChecked()){
16 sliPriority->Enable();
18 sliPriority->Disable();
22 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
25 // Set the editor mode for adding or editing an email address.
27 if (EditMode == FALSE){
30 btnAction->SetLabel(_("Add"));
31 this->SetTitle(_("Add Language"));
33 } else if (EditMode == TRUE){
36 btnAction->SetLabel(_("Modify"));
37 this->SetTitle(_("Modify Language"));
39 std::map<int,int>::iterator intiter;
40 std::map<int,wxString>::iterator striter;
43 // Load the data into the form.
45 striter = LanguageListPtr->find(LanguageListIndex);
47 if (striter->first == LanguageListIndex){
49 strValue = striter->second;
53 txtLanguage->SetValue(strValue);
57 intiter = LanguageListPrefPtr->find(LanguageListIndex);
59 if (intiter->first == LanguageListIndex && intiter->second > 0){
61 sliPriority->SetValue(intiter->second);
62 sliPriority->Enable();
63 chkUsePref->SetValue(TRUE);
69 EditSectionType = SectType;
72 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
77 if (EditorMode == FALSE){
79 // Add the language to the list.
85 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
89 if (EditSectionType == CE_GENERAL){
91 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
93 } else if (EditSectionType == CE_HOME) {
95 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
97 } else if (EditSectionType == CE_WORK) {
99 LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
103 // Add Language priority.
105 if (chkUsePref->IsChecked()){
107 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
111 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
115 // Add the data to the form.
119 coldata.SetId(LanguageListIndex);
120 coldata.SetData(LanguageListIndex);
121 coldata.SetText(txtLanguage->GetValue());
122 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
124 if (chkUsePref->IsChecked()){
126 LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
132 } else if (EditorMode == TRUE){
134 // Edit the language.
138 long longSelected = -1;
140 LanguageListPtr->erase(LanguageListIndex);
141 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
143 LanguageListPrefPtr->erase(LanguageListIndex);
145 if (chkUsePref->IsChecked()){
147 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, sliPriority->GetValue()));
151 LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));
155 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected,
157 wxLIST_STATE_SELECTED);
159 if (longSelected == -1){
163 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());
165 if (chkUsePref->IsChecked()){
167 LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), sliPriority->GetValue()));
171 LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
181 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
190 void frmContactEditorLanguages::SetupPointers(std::map<int, wxString> *LanguageList,
191 std::map<int, wxString> *LanguageListAltID,
192 std::map<int, wxString> *LanguageListPID,
193 std::map<int, wxString> *LanguageListType,
194 std::map<int, wxString> *LanguageListTokens,
195 std::map<int, int> *LanguageListPref,
196 wxListCtrl *LanguageListCtrl,
200 // Setup the pointers so that the data can be processed without
203 LanguageListPtr = LanguageList;
204 LanguageListAltIDPtr = LanguageListAltID;
205 LanguageListPIDPtr = LanguageListPID;
206 LanguageListTypePtr = LanguageListType;
207 LanguageListTokensPtr = LanguageListTokens;
208 LanguageListPrefPtr = LanguageListPref;
209 LanguageListCtrlPtr = LanguageListCtrl;
210 LanguageListIndex = LanguageIndex;