1 #include "frmContactEditorRelated.h"
3 #include "../common/textprocessing.h"
6 frmContactEditorRelated::frmContactEditorRelated( wxWindow* parent )
8 frmContactEditorRelatedADT( parent )
12 sliPriority->Disable();
14 // Setup the list of types for the related drop down box.
16 cmbType->Append(_("Contact"));
17 cmbType->Append(_("Acquaintance"));
18 cmbType->Append(_("Friend"));
19 cmbType->Append(_("Met"));
20 cmbType->Append(_("Co-worker"));
21 cmbType->Append(_("Colleague"));
22 cmbType->Append(_("Co-resident"));
23 cmbType->Append(_("Neighbour"));
24 cmbType->Append(_("Child"));
25 cmbType->Append(_("Parent"));
26 cmbType->Append(_("Sibling"));
27 cmbType->Append(_("Spouse"));
28 cmbType->Append(_("Kin"));
29 cmbType->Append(_("Muse"));
30 cmbType->Append(_("Crush"));
31 cmbType->Append(_("Date"));
32 cmbType->Append(_("Sweetheart"));
33 cmbType->Append(_("Me"));
34 cmbType->Append(_("Agent"));
35 cmbType->Append(_("Emergency"));
39 void frmContactEditorRelated::EnablePriority( wxCommandEvent& event )
41 if (chkUsePref->IsChecked()){
42 sliPriority->Enable();
44 sliPriority->Disable();
48 void frmContactEditorRelated::SetEditorMode(bool EditMode, SectionType SectType)
50 if (EditMode == FALSE){
53 btnAction->SetLabel(_("Add"));
54 this->SetTitle(_("Add Related"));
56 } else if (EditMode == TRUE){
59 btnAction->SetLabel(_("Modify"));
60 this->SetTitle(_("Modify Related"));
62 std::map<int,int>::iterator intiter;
63 std::map<int,wxString>::iterator striter;
66 // Get the related data.
68 striter = RelatedListPtr->find(RelatedListIndex);
70 if (striter->first == RelatedListIndex){
72 strValue = striter->second;
76 txtRelated->SetValue(strValue);
80 // Get the related type.
82 striter = RelatedListRelTypePtr->find(RelatedListIndex);
84 if (striter->first == RelatedListIndex){
86 strValue = striter->second;
90 if (strValue == wxT("contact")){
92 cmbType->SetValue(_("Contact"));
94 } else if (strValue == wxT("acquaintance")){
96 cmbType->SetValue(_("Acquaintance"));
98 } else if (strValue == wxT("friend")){
100 cmbType->SetValue(_("Friend"));
102 } else if (strValue == wxT("met")){
104 cmbType->SetValue(_("Met"));
106 } else if (strValue == wxT("co-worker")){
108 cmbType->SetValue(_("Co-worker"));
110 } else if (strValue == wxT("colleague")){
112 cmbType->SetValue(_("Colleague"));
114 } else if (strValue == wxT("co-resident")){
116 cmbType->SetValue(_("Co-resident"));
118 } else if (strValue == wxT("neighbor")){
120 cmbType->SetValue(_("Neighbour"));
122 } else if (strValue == wxT("child")){
124 cmbType->SetValue(_("Child"));
126 } else if (strValue == wxT("parent")){
128 cmbType->SetValue(_("Parent"));
130 } else if (strValue == wxT("sibling")){
132 cmbType->SetValue(_("Sibling"));
134 } else if (strValue == wxT("spouse")){
136 cmbType->SetValue(_("Spouse"));
138 } else if (strValue == wxT("kin")){
140 cmbType->SetValue(_("Kin"));
142 } else if (strValue == wxT("muse")){
144 cmbType->SetValue(_("Muse"));
146 } else if (strValue == wxT("crush")){
148 cmbType->SetValue(_("Crush"));
150 } else if (strValue == wxT("date")){
152 cmbType->SetValue(_("Date"));
154 } else if (strValue == wxT("sweetheart")){
156 cmbType->SetValue(_("Sweetheart"));
158 } else if (strValue == wxT("me")){
160 cmbType->SetValue(_("Me"));
162 } else if (strValue == wxT("agent")){
164 cmbType->SetValue(_("Agent"));
166 } else if (strValue == wxT("emergency")){
168 cmbType->SetValue(_("Emergency"));
172 cmbType->SetValue(strValue);
178 intiter = RelatedListPrefPtr->find(RelatedListIndex);
180 if (intiter->first == RelatedListIndex && intiter->second > 0){
182 sliPriority->SetValue(intiter->second);
183 sliPriority->Enable();
184 chkUsePref->SetValue(TRUE);
190 EditSectionType = SectType;
194 void frmContactEditorRelated::ProcessData( wxCommandEvent& event )
198 if (EditorMode == FALSE){
202 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
204 // Work out the type of contact.
206 strValue = cmbType->GetValue();
208 if (strValue == _("Contact")){
210 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
212 } else if (strValue == _("Acquaintance")){
214 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
216 } else if (strValue == _("Friend")){
218 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
220 } else if (strValue == _("Met")){
222 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
224 } else if (strValue == _("Co-worker")){
226 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
228 } else if (strValue == _("Colleague")){
230 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
232 } else if (strValue == _("Co-resident")){
234 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
236 } else if (strValue == _("Neighbour")){
238 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
240 } else if (strValue == _("Child")){
242 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
244 } else if (strValue == _("Parent")){
246 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
248 } else if (strValue == _("Sibling")){
250 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
252 } else if (strValue == _("Spouse")){
254 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
256 } else if (strValue == _("Kin")){
258 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
260 } else if (strValue == _("Muse")){
262 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
264 } else if (strValue == _("Crush")){
266 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
268 } else if (strValue == _("Date")){
270 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
272 } else if (strValue == _("Sweetheart")){
274 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
276 } else if (strValue == _("Me")){
278 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
280 } else if (strValue == _("Agent")){
282 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
284 } else if (strValue == _("Emergency")){
286 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
290 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
296 if (EditSectionType == CE_GENERAL){
298 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("")));
300 } else if (EditSectionType == CE_HOME) {
302 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("home")));
304 } else if (EditSectionType == CE_WORK) {
306 RelatedListTypePtr->insert(std::make_pair(RelatedListIndex, wxT("work")));
310 // Add Related Priority.
312 if (chkUsePref->IsChecked()){
314 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
318 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
326 coldata.SetId(RelatedListIndex);
327 coldata.SetData(RelatedListIndex);
328 coldata.SetText(cmbType->GetValue());
329 ListCtrlIndex = RelatedListCtrlPtr->InsertItem(coldata);
331 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 1, txtRelated->GetValue());
333 if (chkUsePref->IsChecked()){
335 RelatedListCtrlPtr->SetItem(ListCtrlIndex, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
341 } else if (EditorMode == TRUE) {
344 long longSelected = -1;
346 // Work out the type of contact.
348 strValue = cmbType->GetValue();
350 RelatedListRelTypePtr->erase(RelatedListIndex);
352 if (strValue == _("Contact")){
354 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("contact")));
356 } else if (strValue == _("Acquaintance")){
358 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("acquaintance")));
360 } else if (strValue == _("Friend")){
362 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("friend")));
364 } else if (strValue == _("Met")){
366 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("met")));
368 } else if (strValue == _("Co-worker")){
370 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-worker")));
372 } else if (strValue == _("Colleague")){
374 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("colleague")));
376 } else if (strValue == _("Co-resident")){
378 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("co-resident")));
380 } else if (strValue == _("Neighbour")){
382 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("neighbor")));
384 } else if (strValue == _("Child")){
386 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("child")));
388 } else if (strValue == _("Parent")){
390 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("parent")));
392 } else if (strValue == _("Sibling")){
394 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sibling")));
396 } else if (strValue == _("Spouse")){
398 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("spouse")));
400 } else if (strValue == _("Kin")){
402 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("kin")));
404 } else if (strValue == _("Muse")){
406 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("muse")));
408 } else if (strValue == _("Crush")){
410 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("crush")));
412 } else if (strValue == _("Date")){
414 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("date")));
416 } else if (strValue == _("Sweetheart")){
418 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("sweetheart")));
420 } else if (strValue == _("Me")){
422 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("me")));
424 } else if (strValue == _("Agent")){
426 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("agent")));
428 } else if (strValue == _("Emergency")){
430 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, wxT("emergency")));
434 RelatedListRelTypePtr->insert(std::make_pair(RelatedListIndex, strValue));
438 RelatedListPrefPtr->erase(RelatedListIndex);
440 if (chkUsePref->IsChecked()){
442 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, sliPriority->GetValue()));
446 RelatedListPrefPtr->insert(std::make_pair(RelatedListIndex, 0));
450 // Get the related person/details.
452 RelatedListPtr->erase(RelatedListIndex);
453 RelatedListPtr->insert(std::make_pair(RelatedListIndex, txtRelated->GetValue()));
457 longSelected = RelatedListCtrlPtr->GetNextItem(longSelected,
459 wxLIST_STATE_SELECTED);
461 if (longSelected == -1){
465 RelatedListCtrlPtr->SetItem(longSelected, 0, cmbType->GetValue());
466 RelatedListCtrlPtr->SetItem(longSelected, 1, txtRelated->GetValue());
468 if (chkUsePref->IsChecked()){
470 RelatedListCtrlPtr->SetItem(longSelected, 2, wxString::Format(wxT("%i"), sliPriority->GetValue()));
474 RelatedListCtrlPtr->SetItem(longSelected, 2, wxT(""));
483 void frmContactEditorRelated::CloseWindow( wxCommandEvent& event )
488 void frmContactEditorRelated::SetupPointers(std::map<int, wxString> *RelatedList,
489 std::map<int, wxString> *RelatedListRelType,
490 std::map<int, wxString> *RelatedListAltID,
491 std::map<int, wxString> *RelatedListPID,
492 std::map<int, wxString> *RelatedListType,
493 std::map<int, wxString> *RelatedListTokens,
494 std::map<int, int> *RelatedListPref,
495 wxListCtrl *RelatedListCtrl,
499 RelatedListPtr = RelatedList;
500 RelatedListRelTypePtr = RelatedListRelType;
501 RelatedListAltIDPtr = RelatedListAltID;
502 RelatedListPIDPtr = RelatedListPID;
503 RelatedListTypePtr = RelatedListType;
504 RelatedListTokensPtr = RelatedListTokens;
505 RelatedListPrefPtr = RelatedListPref;
506 RelatedListCtrlPtr = RelatedListCtrl;
507 RelatedListIndex = RelatedIndex;