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