Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorLanguages.cpp
1 // frmContactEditorLanguages.cpp - frmContactEditorLanguages form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
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.
10 //
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.
15 //
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"
21 #include <map>
23 frmContactEditorLanguages::frmContactEditorLanguages( wxWindow* parent )
24 :
25 frmContactEditorLanguagesADT( parent )
26 {
27         
28         // Setup the window.
29         
30         EditorMode = FALSE;
31         priorityCtrl = new XABPriorityCtrl(tabGeneral);
32         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
33         szrGeneral->Layout();
34         
35 }
37 void frmContactEditorLanguages::SetEditorMode(bool EditMode, SectionType SectType)
38 {
40         // Set the editor mode for adding or editing an email address.
42         if (EditMode == FALSE){
43         
44                 EditorMode = FALSE;
45                 btnAction->SetLabel(_("Add"));
46                 this->SetTitle(_("Add Language"));
47         
48         } else if (EditMode == TRUE){
49         
50                 EditorMode = TRUE;
51                 btnAction->SetLabel(_("Modify"));
52                 this->SetTitle(_("Modify Language"));
53         
54                 std::map<int,int>::iterator intiter;
55                 std::map<int,wxString>::iterator striter;
56                 wxString strValue;
57                 
58                 // Load the data into the form.
59                 
60                 striter = LanguageListPtr->find(LanguageListIndex);
61                  
62                 if (striter->first == LanguageListIndex){
63                 
64                         strValue = striter->second;
65                 
66                 }
67                 
68                 txtLanguage->SetValue(strValue);
69                 
70                 // Setup the Slider.
71                 
72                 intiter = LanguageListPrefPtr->find(LanguageListIndex);
73                 
74                 if (intiter->first == LanguageListIndex && intiter->second > 0 &&
75                         intiter != LanguageListPrefPtr->end()){
76                 
77                         priorityCtrl->SetValue(intiter->second);
78                         priorityCtrl->EnablePriority(true);
79                 
80                 }       
81                 
82         }
83         
84         EditSectionType = SectType;
85 }
87 void frmContactEditorLanguages::ProcessAction( wxCommandEvent& event )
88 {
90         // Process the action.
91         
92         long ListCtrlIndex;
94         if (EditorMode == FALSE){
95         
96                 // Add the language to the list.
98                 wxString strValue;
99                 
100                 // Add language.
101                 
102                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
103                 
104                 // Add Email type.
105                 
106                 if (EditSectionType == CE_GENERAL){
107                 
108                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("")));
109                 
110                 } else if (EditSectionType == CE_HOME) {
111                 
112                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("home")));
113                 
114                 } else if (EditSectionType == CE_WORK) {
115                 
116                         LanguageListTypePtr->insert(std::make_pair(LanguageListIndex, wxT("work")));
117                 
118                 }
119                 
120                 // Add Language priority.
121                 
122                 if (priorityCtrl->IsPriorityChecked()){
123                 
124                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
125                 
126                 } else {
127                 
128                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
129                 
130                 }               
131                 
132                 // Add the data to the form.
133                 
134                 wxListItem coldata;
135                 
136                 coldata.SetId(LanguageListIndex);
137                 coldata.SetData(LanguageListIndex);             
138                 coldata.SetText(txtLanguage->GetValue());
139                 ListCtrlIndex = LanguageListCtrlPtr->InsertItem(coldata);
140                 
141                 if (priorityCtrl->IsPriorityChecked()){
142                 
143                         LanguageListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
144                 
145                 }
146                 
147                 this->Close();          
148         
149         } else if (EditorMode == TRUE){
150         
151                 // Edit the language.
152                 
153                 wxString strAddress;
154                 wxString strValue;
155                 long longSelected = -1;
157                 LanguageListPtr->erase(LanguageListIndex);
158                 LanguageListPtr->insert(std::make_pair(LanguageListIndex, txtLanguage->GetValue()));
159                 
160                 LanguageListPrefPtr->erase(LanguageListIndex);
161                 
162                 if (priorityCtrl->IsPriorityChecked()){
163                 
164                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, priorityCtrl->GetValue()));
165                 
166                 } else {
167                 
168                         LanguageListPrefPtr->insert(std::make_pair(LanguageListIndex, 0));              
169                 
170                 }
171                 
172                 longSelected = LanguageListCtrlPtr->GetNextItem(longSelected, 
173                         wxLIST_NEXT_ALL,
174                         wxLIST_STATE_SELECTED);
175                         
176                 if (longSelected == -1){
177                         return;
178                 }
179                 
180                 LanguageListCtrlPtr->SetItem(longSelected, 0, txtLanguage->GetValue());         
181                 
182                 if (priorityCtrl->IsPriorityChecked()){
183                 
184                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
185                 
186                 } else {
187                 
188                         LanguageListCtrlPtr->SetItem(longSelected, 1, wxT(""));
189                 
190                 }       
191                         
192                 this->Close();
193         
194         }
198 void frmContactEditorLanguages::CloseWindow( wxCommandEvent& event )
201         // Close the window.
202         
203         this->Close();
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,
214         int LanguageIndex )
217         // Setup the pointers so that the data can be processed without
218         // duplication.
220         LanguageListPtr = LanguageList;
221         LanguageListAltIDPtr = LanguageListAltID;
222         LanguageListPIDPtr = LanguageListPID;
223         LanguageListTypePtr = LanguageListType;
224         LanguageListTokensPtr = LanguageListTokens;
225         LanguageListPrefPtr = LanguageListPref;
226         LanguageListCtrlPtr = LanguageListCtrl;
227         LanguageListIndex = LanguageIndex;
228         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy