1 // frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
27 frmContactEditorTitlesADT( parent )
33 priorityCtrl = new XABPriorityCtrl(tabGeneral);
34 szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
37 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
42 // Set if the editor is adding or editing an address.
48 if (EditorMode == FALSE){
52 // Get the website address.
54 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
56 // Get the type of website.
58 if (EditSectionType == CE_GENERAL){
60 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
62 } else if (EditSectionType == CE_HOME) {
64 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
66 } else if (EditSectionType == CE_WORK) {
68 TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
72 // Add the website priority.
74 if (priorityCtrl->IsPriorityChecked()){
76 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
80 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
88 coldata.SetId(TitlesListIndex);
89 coldata.SetData(TitlesListIndex);
90 coldata.SetText(txtTitle->GetValue());
91 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
93 if (priorityCtrl->IsPriorityChecked()){
95 TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
104 long longSelected = -1;
106 TitlesListPtr->erase(TitlesListIndex);
107 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
109 // Update the slider priority.
111 TitlesListPrefPtr->erase(TitlesListIndex);
113 if (priorityCtrl->IsPriorityChecked()){
115 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
119 TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
125 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected,
127 wxLIST_STATE_SELECTED);
129 if (longSelected == -1){
133 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
135 if (priorityCtrl->IsPriorityChecked()){
137 TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
141 TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
150 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
153 // Set the editor mode.
155 // Set if the editor is adding or editing an address.
159 if (EditMode == FALSE){
162 btnAction->SetLabel(_("Add"));
163 this->SetTitle(_("Add Title"));
165 } else if (EditMode == TRUE){
168 btnAction->SetLabel(_("Modify"));
169 this->SetTitle(_("Modify Title"));
171 std::map<int,int>::iterator intiter;
172 std::map<int,wxString>::iterator striter;
175 // Load the data into the form. Get the website.
177 striter = TitlesListPtr->find(TitlesListIndex);
179 if (striter->first == TitlesListIndex &&
180 striter != TitlesListPtr->end()){
182 strValue = striter->second;
186 txtTitle->SetValue(strValue);
190 // Get the website priority.
192 intiter = TitlesListPrefPtr->find(TitlesListIndex);
194 if (intiter->first == TitlesListIndex && intiter->second > 0 &&
195 intiter != TitlesListPrefPtr->end()){
197 priorityCtrl->SetValue(intiter->second);
198 priorityCtrl->EnablePriority(true);
204 EditSectionType = SectType;
208 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
217 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
218 std::map<int, wxString> *TitlesListLanguage,
219 std::map<int, wxString> *TitlesListAltID,
220 std::map<int, wxString> *TitlesListPID,
221 std::map<int, wxString> *TitlesListType,
222 std::map<int, wxString> *TitlesListTokens,
223 std::map<int, int> *TitlesListPref,
224 wxListCtrl *TitlesListCtrl,
228 // Setup the pointers.
230 TitlesListPtr = TitlesList;
231 TitlesListLanguagePtr = TitlesListLanguage;
232 TitlesListAltIDPtr = TitlesListAltID;
233 TitlesListPIDPtr = TitlesListPID;
234 TitlesListTypePtr = TitlesListType;
235 TitlesListTokensPtr = TitlesListTokens;
236 TitlesListPrefPtr = TitlesListPref;
237 TitlesListCtrlPtr = TitlesListCtrl;
238 TitlesListIndex = TitlesIndex;