Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorTitles.cpp
1 // frmContactEditorTitles.cpp - frmContactEditorTitles 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 "frmContactEditorTitles.h"
21 #include <map>
22 #include "../enums.h"
23 #include "../common/textprocessing.h"
25 frmContactEditorTitles::frmContactEditorTitles( wxWindow* parent )
26 :
27 frmContactEditorTitlesADT( parent )
28 {
29         
30         // Setup the window.
31         
32         EditorMode = FALSE;
33         priorityCtrl = new XABPriorityCtrl(tabGeneral);
34         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
35         szrGeneral->Layout();
37 }
39 void frmContactEditorTitles::ProcessAction( wxCommandEvent& event )
40 {
41         
42         // Process action.
43         
44         // Set if the editor is adding or editing an address.
45         // FALSE = Add
46         // TRUE = Edit
48         long ListCtrlIndex;
49         
50         if (EditorMode == FALSE){
51         
52                 wxString strValue;
53                 
54                 // Get the website address.
55                 
56                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
57                 
58                 // Get the type of website.
59                 
60                 if (EditSectionType == CE_GENERAL){
61                 
62                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("")));
63                 
64                 } else if (EditSectionType == CE_HOME) {
65                 
66                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("home")));
67                 
68                 } else if (EditSectionType == CE_WORK) {
69                 
70                         TitlesListTypePtr->insert(std::make_pair(TitlesListIndex, wxT("work")));
71                 
72                 }
73                 
74                 // Add the website priority.
75                 
76                 if (priorityCtrl->IsPriorityChecked()){
77                 
78                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
79                 
80                 } else {
81                 
82                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));          
83                 
84                 }
85                 
86                 // Add to the form.
87                 
88                 wxListItem coldata;
89                 
90                 coldata.SetId(TitlesListIndex);
91                 coldata.SetData(TitlesListIndex);               
92                 coldata.SetText(txtTitle->GetValue());
93                 ListCtrlIndex = TitlesListCtrlPtr->InsertItem(coldata);
94                 
95                 if (priorityCtrl->IsPriorityChecked()){
96                 
97                         TitlesListCtrlPtr->SetItem(ListCtrlIndex, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
98                 
99                 }               
100         
101                 this->Close();          
102         
103         } else {
104         
105                 // Update the title.
106                 long longSelected = -1;         
107                 wxString strValue;
108                 TitlesListPtr->erase(TitlesListIndex);
109                 TitlesListPtr->insert(std::make_pair(TitlesListIndex, txtTitle->GetValue()));
110                 
111                 // Update the slider priority.
112                 
113                 TitlesListPrefPtr->erase(TitlesListIndex);
114                 
115                 if (priorityCtrl->IsPriorityChecked()){
116                 
117                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, priorityCtrl->GetValue()));
118                 
119                 } else {
120                 
121                         TitlesListPrefPtr->insert(std::make_pair(TitlesListIndex, 0));
122                 
123                 }               
124                 
125                 // Update the form.
126                 
127                 longSelected = TitlesListCtrlPtr->GetNextItem(longSelected, 
128                         wxLIST_NEXT_ALL,
129                         wxLIST_STATE_SELECTED);
130                         
131                 if (longSelected == -1){
132                         return;
133                 }               
134                 
135                 TitlesListCtrlPtr->SetItem(longSelected, 0, txtTitle->GetValue());
136                 
137                 if (priorityCtrl->IsPriorityChecked()){
138                 
139                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
140                 
141                 } else {
142                 
143                         TitlesListCtrlPtr->SetItem(longSelected, 1, wxT(""));
144                 
145                 }               
146         
147                 this->Close();
148         
149         }
152 void frmContactEditorTitles::SetEditorMode(bool EditMode, SectionType SectType)
154         
155         // Set the editor mode.
156         
157         // Set if the editor is adding or editing an address.
158         // FALSE = Add
159         // TRUE = Edit
160         
161         if (EditMode == FALSE){
162         
163                 EditorMode = FALSE;
164                 btnAction->SetLabel(_("Add"));
165                 this->SetTitle(_("Add Title"));
166         
167         } else if (EditMode == TRUE){
168         
169                 EditorMode = TRUE;
170                 btnAction->SetLabel(_("Modify"));
171                 this->SetTitle(_("Modify Title"));
172                 
173                 std::map<int,int>::iterator intiter;
174                 std::map<int,wxString>::iterator striter;               
175                 wxString strValue;
176                 
177                 // Load the data into the form. Get the website.
178                 
179                 striter = TitlesListPtr->find(TitlesListIndex);
180                  
181                 if (striter->first == TitlesListIndex &&
182                         striter != TitlesListPtr->end()){
183                 
184                         strValue = striter->second;
185                 
186                 }
187                 
188                 txtTitle->SetValue(strValue);
189                 
190                 strValue.Clear();
191                 
192                 // Get the website priority.
193                 
194                 intiter = TitlesListPrefPtr->find(TitlesListIndex);
195                 
196                 if (intiter->first == TitlesListIndex && intiter->second > 0 &&
197                         intiter != TitlesListPrefPtr->end()){
198                 
199                         priorityCtrl->SetValue(intiter->second);
200                         priorityCtrl->EnablePriority(true);
201                 
202                 }       
203                 
204         }
205         
206         EditSectionType = SectType;
207                 
210 void frmContactEditorTitles::CloseWindow( wxCommandEvent& event )
212         
213         // Close the window.
214         
215         this->Close();
216         
219 void frmContactEditorTitles::SetupPointers(std::map<int, wxString> *TitlesList,
220         std::map<int, wxString> *TitlesListLanguage,
221         std::map<int, wxString> *TitlesListAltID,
222         std::map<int, wxString> *TitlesListPID,
223         std::map<int, wxString> *TitlesListType,
224         std::map<int, wxString> *TitlesListTokens,
225         std::map<int, int> *TitlesListPref,
226         wxListCtrl *TitlesListCtrl,
227         int TitlesIndex )
230         // Setup the pointers.
231         
232         TitlesListPtr = TitlesList;
233         TitlesListLanguagePtr = TitlesListLanguage;
234         TitlesListAltIDPtr = TitlesListAltID;
235         TitlesListPIDPtr = TitlesListPID;
236         TitlesListTypePtr = TitlesListType;
237         TitlesListTokensPtr = TitlesListTokens;
238         TitlesListPrefPtr = TitlesListPref;
239         TitlesListCtrlPtr = TitlesListCtrl;
240         TitlesListIndex = TitlesIndex;
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