Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmContactEditor(*): Call Layout on szrGeneral after adding priorty control
[xestiaab/.git] / source / contacteditor / frmContactEditorRelated.cpp
1 // frmContactEditorRelated.cpp - frmContactEditorRelated 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 "frmContactEditorRelated.h"
20 #include <map>
21 #include "../common/textprocessing.h"
22 #include "../enums.h"
24 frmContactEditorRelated::frmContactEditorRelated( wxWindow* parent )
25 :
26 frmContactEditorRelatedADT( parent )
27 {
28         
29         // Setup the window.
30         
31         EditorMode = FALSE;
32         priorityCtrl = new XABPriorityCtrl(tabGeneral);
33         szrGeneral->Add(priorityCtrl, 1, wxEXPAND, 5);
34         szrGeneral->Layout();
35         
36         // Setup the list of types for the related drop down box.
37         
38         cmbType->Append(_("Contact"));
39         cmbType->Append(_("Acquaintance"));     
40         cmbType->Append(_("Friend"));   
41         cmbType->Append(_("Met"));
42         cmbType->Append(_("Co-worker"));
43         cmbType->Append(_("Colleague"));
44         cmbType->Append(_("Co-resident"));
45         cmbType->Append(_("Neighbour"));
46         cmbType->Append(_("Child"));
47         cmbType->Append(_("Parent"));
48         cmbType->Append(_("Sibling"));  
49         cmbType->Append(_("Spouse"));
50         cmbType->Append(_("Kin"));
51         cmbType->Append(_("Muse"));
52         cmbType->Append(_("Crush"));
53         cmbType->Append(_("Date"));
54         cmbType->Append(_("Sweetheart"));
55         cmbType->Append(_("Me"));
56         cmbType->Append(_("Agent"));
57         cmbType->Append(_("Emergency"));        
58         
59 }
61 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
62 {
63         
64         // Set the editor mode.
65         
66         if (EditMode == FALSE){
67         
68                 EditorMode = FALSE;
69                 btnAction->SetLabel(_("Add"));
70                 this->SetTitle(_("Add Related"));
71         
72         } else if (EditMode == TRUE){
73         
74                 EditorMode = TRUE;
75                 btnAction->SetLabel(_("Modify"));
76                 this->SetTitle(_("Modify Related"));
77                 
78                 std::map<int,int>::iterator intiter;
79                 std::map<int,wxString>::iterator striter;               
80                 wxString strValue;
81                 
82                 // Get the related data.
83                 
84                 striter = RelatedListPtr->find(RelatedListIndex);
85                  
86                 if (striter->first == RelatedListIndex){
87                 
88                         strValue = striter->second;
89                 
90                 }
91                 
92                 txtRelated->SetValue(strValue);
93                 
94                 strValue.Clear();
95                 
96                 // Get the related type.
97                 
98                 striter = RelatedListRelTypePtr->find(RelatedListIndex);
99                  
100                 if (striter->first == RelatedListIndex &&
101                         striter != RelatedListRelTypePtr->end()){
102                 
103                         strValue = striter->second;
104                 
105                 }
106                 
107                 if (strValue == wxT("contact")){
108                 
109                         cmbType->SetValue(_("Contact"));
110                 
111                 } else if (strValue == wxT("acquaintance")){
112                 
113                         cmbType->SetValue(_("Acquaintance"));
114                 
115                 } else if (strValue == wxT("friend")){
116                 
117                         cmbType->SetValue(_("Friend"));
118                 
119                 } else if (strValue == wxT("met")){
120                 
121                         cmbType->SetValue(_("Met"));
122                 
123                 } else if (strValue == wxT("co-worker")){
124                 
125                         cmbType->SetValue(_("Co-worker"));
126                 
127                 } else if (strValue == wxT("colleague")){
128                 
129                         cmbType->SetValue(_("Colleague"));
130                 
131                 } else if (strValue == wxT("co-resident")){
132                 
133                         cmbType->SetValue(_("Co-resident"));
134                 
135                 } else if (strValue == wxT("neighbor")){
136                 
137                         cmbType->SetValue(_("Neighbour"));
138                 
139                 } else if (strValue == wxT("child")){
140                 
141                         cmbType->SetValue(_("Child"));
142                 
143                 } else if (strValue == wxT("parent")){
144                 
145                         cmbType->SetValue(_("Parent"));
146                 
147                 } else if (strValue == wxT("sibling")){
148                 
149                         cmbType->SetValue(_("Sibling"));
150                 
151                 } else if (strValue == wxT("spouse")){
152                 
153                         cmbType->SetValue(_("Spouse"));
154                 
155                 } else if (strValue == wxT("kin")){
156                 
157                         cmbType->SetValue(_("Kin"));
158                 
159                 } else if (strValue == wxT("muse")){
160                 
161                         cmbType->SetValue(_("Muse"));
162                 
163                 } else if (strValue == wxT("crush")){
164                 
165                         cmbType->SetValue(_("Crush"));
166                 
167                 } else if (strValue == wxT("date")){
168                 
169                         cmbType->SetValue(_("Date"));
170                 
171                 } else if (strValue == wxT("sweetheart")){
172                 
173                         cmbType->SetValue(_("Sweetheart"));
174                 
175                 } else if (strValue == wxT("me")){
176                 
177                         cmbType->SetValue(_("Me"));
178                 
179                 } else if (strValue == wxT("agent")){
180                 
181                         cmbType->SetValue(_("Agent"));
182                 
183                 } else if (strValue == wxT("emergency")){
184                 
185                         cmbType->SetValue(_("Emergency"));
186                 
187                 } else {
188                 
189                         cmbType->SetValue(strValue);
190                 
191                 }
192                 
193                 // Setup the Slider.
194                 
195                 intiter = RelatedListPrefPtr->find(RelatedListIndex);
196                 
197                 if (intiter->first == RelatedListIndex && intiter->second > 0 &&
198                         intiter != RelatedListPrefPtr->end()){
199                 
200                         priorityCtrl->SetValue(intiter->second);
201                         priorityCtrl->EnablePriority(true);
202                 
203                 }
204                 
205         }
206         
207         EditSectionType = SectType;     
208         
211 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
213         
214         // Process data.
215         
216         long ListCtrlIndex;
217         
218         if (EditorMode == FALSE){
220                 wxString strValue;
222                 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
223                 
224                 // Work out the type of contact.
225                 
226                 strValue = cmbType->GetValue();         
227                 
228                 if (strValue == _("Contact")){
229                 
230                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
231                 
232                 } else if (strValue == _("Acquaintance")){
233                 
234                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
235                 
236                 } else if (strValue == _("Friend")){
237                 
238                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
239                 
240                 } else if (strValue == _("Met")){
241                 
242                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
243                 
244                 } else if (strValue == _("Co-worker")){
245                 
246                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
247                 
248                 } else if (strValue == _("Colleague")){
249                 
250                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
251                 
252                 } else if (strValue == _("Co-resident")){
253                 
254                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
255                 
256                 } else if (strValue == _("Neighbour")){
257                 
258                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
259                 
260                 } else if (strValue == _("Child")){
261                 
262                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
263                 
264                 } else if (strValue == _("Parent")){
265                 
266                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
267                 
268                 } else if (strValue == _("Sibling")){
269                 
270                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
271                 
272                 } else if (strValue == _("Spouse")){
273                 
274                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
275                 
276                 } else if (strValue == _("Kin")){
277                 
278                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
279                 
280                 } else if (strValue == _("Muse")){
281                 
282                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
283                 
284                 } else if (strValue == _("Crush")){
285                 
286                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
287                 
288                 } else if (strValue == _("Date")){
289                 
290                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
291                 
292                 } else if (strValue == _("Sweetheart")){
293                 
294                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
295                 
296                 } else if (strValue == _("Me")){
297                 
298                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
299                 
300                 } else if (strValue == _("Agent")){
301                 
302                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
303                 
304                 } else if (strValue == _("Emergency")){
305                 
306                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
307                 
308                 } else {
309                 
310                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
311                 
312                 }
313                 
314                 // Add Related type.
315                 
316                 if (EditSectionType == CE_GENERAL){
317                 
318                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
319                 
320                 } else if (EditSectionType == CE_HOME) {
321                 
322                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
323                 
324                 } else if (EditSectionType == CE_WORK) {
325                 
326                         RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
327                 
328                 }       
329                 
330                 // Add Related Priority.
331                 
332                 if (priorityCtrl->IsPriorityChecked()){
333                 
334                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
335                 
336                 } else {
337                 
338                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));                
339                 
340                 }
341                 
342                 // Add to the form.
343                 
344                 wxListItem coldata;
345                 
346                 coldata.SetId(RelatedListIndex);
347                 coldata.SetData(RelatedListIndex);              
348                 coldata.SetText(cmbType->GetValue());
349                 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
350                 
351                 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
352                 
353                 if (priorityCtrl->IsPriorityChecked()){
354                 
355                         RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
356                 
357                 }               
358         
359                 this->Close();
360         
361         } else if (EditorMode == TRUE) {
362         
363                 wxString strValue;
364                 long longSelected = -1;
365         
366                 // Work out the type of contact.
367                 
368                 strValue = cmbType->GetValue();         
369                 
370                 RelatedListRelTypePtr->erase(RelatedListIndex);
371                 
372                 if (strValue == _("Contact")){
373                 
374                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
375                 
376                 } else if (strValue == _("Acquaintance")){
377                 
378                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
379                 
380                 } else if (strValue == _("Friend")){
381                 
382                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
383                 
384                 } else if (strValue == _("Met")){
385                 
386                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
387                 
388                 } else if (strValue == _("Co-worker")){
389                 
390                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
391                 
392                 } else if (strValue == _("Colleague")){
393                 
394                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
395                 
396                 } else if (strValue == _("Co-resident")){
397                 
398                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
399                 
400                 } else if (strValue == _("Neighbour")){
401                 
402                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
403                 
404                 } else if (strValue == _("Child")){
405                 
406                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
407                 
408                 } else if (strValue == _("Parent")){
409                 
410                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
411                 
412                 } else if (strValue == _("Sibling")){
413                 
414                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
415                 
416                 } else if (strValue == _("Spouse")){
417                 
418                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
419                 
420                 } else if (strValue == _("Kin")){
421                 
422                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
423                 
424                 } else if (strValue == _("Muse")){
425                 
426                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
427                 
428                 } else if (strValue == _("Crush")){
429                 
430                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
431                 
432                 } else if (strValue == _("Date")){
433                 
434                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
435                 
436                 } else if (strValue == _("Sweetheart")){
437                 
438                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
439                 
440                 } else if (strValue == _("Me")){
441                 
442                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
443                 
444                 } else if (strValue == _("Agent")){
445                 
446                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
447                 
448                 } else if (strValue == _("Emergency")){
449                 
450                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
451                 
452                 } else {
453                 
454                         RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
455                 
456                 }       
457                 
458                 RelatedListPrefPtr->erase(RelatedListIndex);
459                 
460                 if (priorityCtrl->IsPriorityChecked()){
461                 
462                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, priorityCtrl->GetValue()));
463                 
464                 } else {
465                 
466                         RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
467                 
468                 }
469                 
470                 // Get the related person/details.
471                 
472                 RelatedListPtr->erase(RelatedListIndex);
473                 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));               
474                 
475                 // Update the form.
476                 
477                 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected, 
478                         wxLIST_NEXT_ALL,
479                         wxLIST_STATE_SELECTED);
480                         
481                 if (longSelected == -1){
482                         return;
483                 }               
484                 
485                 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
486                 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
487                 
488                 if (priorityCtrl->IsPriorityChecked()){
489                 
490                         RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), priorityCtrl->GetValue()));
491                 
492                 } else {
493                 
494                         RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
495                 
496                 }       
497         
498                 this->Close();
499         
500         }       
503 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
505         
506         // Close this window.
507         
508         this->Close();
509         
512 void frmContactEditorRelated::SetupPointers(std::map<int, wxString> *RelatedList,
513         std::map<int, wxString> *RelatedListRelType,
514         std::map<int, wxString> *RelatedListAltID,
515         std::map<int, wxString> *RelatedListPID,
516         std::map<int, wxString> *RelatedListType,
517         std::map<int, wxString> *RelatedListTokens,                     
518         std::map<int, int> *RelatedListPref,
519         wxListCtrl *RelatedListCtrl,
520         int RelatedIndex )
523         // Setup the pointers.
524         
525         RelatedListPtr = RelatedList;
526         RelatedListRelTypePtr = RelatedListRelType;     
527         RelatedListAltIDPtr = RelatedListAltID;
528         RelatedListPIDPtr = RelatedListPID;
529         RelatedListTypePtr = RelatedListType;
530         RelatedListTokensPtr = RelatedListTokens;
531         RelatedListPrefPtr = RelatedListPref;
532         RelatedListCtrlPtr = RelatedListCtrl;
533         RelatedListIndex = RelatedIndex;
534         
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