Bumped copyright dates for 2013
[barry.git] / desktop / src / TaskEditDlg.cc
blob2ce6d3f2dd365fe2798b63e36f9f531b52d328a4
1 ///
2 /// \file TaskEditDlg.cc
3 /// Dialog class to handle the editing of the Task record
4 ///
6 /*
7 Copyright (C) 2012-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "TaskEditDlg.h"
23 #include "windowids.h"
24 #include <wx/valgen.h>
25 #include "wxval.h"
26 #include "util.h"
28 using namespace std;
29 using namespace Barry;
31 // begin wxGlade: ::extracode
32 // end wxGlade
35 //////////////////////////////////////////////////////////////////////////////
36 // TaskEditDlg class
38 TaskEditDlg::TaskEditDlg(wxWindow* parent,
39 Barry::Task &rec,
40 bool editable,
41 const Barry::TimeZones *device_zones)
42 : wxDialog(parent, Dialog_TaskEdit, _W("Task Record"))
43 , m_zones(device_zones ? device_zones : &m_static_zones)
44 , m_rec(rec)
45 , m_reminder_hours(0)
46 , m_reminder_minutes(0)
47 , m_interval(0)
48 , m_relative_date(false)
50 // set all weekday 'bits' to false
51 for( int i = 0; i < 7; i++ )
52 m_weekdays[i] = false;
54 if( editable ) {
55 bottom_buttons = CreateButtonSizer(wxOK | wxCANCEL);
57 else {
58 bottom_buttons = CreateButtonSizer(wxCANCEL);
61 // begin wxGlade: TaskEditDlg::TaskEditDlg
62 label_1 = new wxStaticText(this, wxID_ANY, _W("Task:"));
63 m_TaskSummary = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
64 static_line_1 = new wxStaticLine(this, wxID_ANY);
65 label_2 = new wxStaticText(this, wxID_ANY, _W("Status:"));
67 const wxString m_StatusChoice_choices[] = {
68 wxT("Not Started"),
69 wxT("In Progress"),
70 wxT("Completed"),
71 wxT("Waiting"),
72 wxT("Deferred")
75 wxArrayString m_StatusChoice_choices;
76 m_StatusChoice_choices.Add( _W("Not Started") );
77 m_StatusChoice_choices.Add( _W("In Progress") );
78 m_StatusChoice_choices.Add( _W("Completed") );
79 m_StatusChoice_choices.Add( _W("Waiting") );
80 m_StatusChoice_choices.Add( _W("Deferred") );
82 m_StatusChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_StatusChoice_choices, 0);
83 label_9 = new wxStaticText(this, wxID_ANY, _W("Priority:"));
85 const wxString m_PriorityChoice_choices[] = {
86 wxT("High"),
87 wxT("Normal"),
88 wxT("Low")
91 wxArrayString m_PriorityChoice_choices;
92 m_PriorityChoice_choices.Add( _W("High") );
93 m_PriorityChoice_choices.Add( _W("Normal") );
94 m_PriorityChoice_choices.Add( _W("Low") );
96 m_PriorityChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_PriorityChoice_choices, 0);
97 label_5 = new wxStaticText(this, wxID_ANY, _W("Due:"));
98 m_DueCheck = new wxCheckBox(this, Dialog_TaskEdit_DueCheck, wxEmptyString);
99 m_DueDateCtrl = new wxDatePickerCtrl(this, Dialog_TaskEdit_DueDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
100 m_DueHoursSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_DueHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
101 label_11 = new wxStaticText(this, wxID_ANY, wxT(":"));
102 m_DueMinutesSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_DueMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
103 label_8 = new wxStaticText(this, wxID_ANY, _W("Time Zone:"));
104 const wxString m_TimezoneChoice_choices[] = {
105 wxT("System Time Zone")
107 m_TimezoneChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 1, m_TimezoneChoice_choices, 0);
108 label_10 = new wxStaticText(this, wxID_ANY, _W("Reminder:"));
109 m_ReminderCheck = new wxCheckBox(this, Dialog_TaskEdit_ReminderCheck, wxEmptyString);
110 m_ReminderDateCtrl = new wxDatePickerCtrl(this, Dialog_TaskEdit_ReminderDateCtrl);
111 m_ReminderHoursSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_ReminderHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
112 label_6 = new wxStaticText(this, wxID_ANY, wxT(":"));
113 m_ReminderMinutesSpinner = new wxSpinCtrl(this, Dialog_TaskEdit_ReminderMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
114 static_line_2 = new wxStaticLine(this, wxID_ANY);
115 label_18 = new wxStaticText(this, wxID_ANY, _W("Recurrence:"));
117 const wxString m_RecurrenceChoice_choices[] = {
118 wxT("None"),
119 wxT("Daily"),
120 wxT("Weekly"),
121 wxT("Monthly"),
122 wxT("Yearly")
125 wxArrayString m_RecurrenceChoice_choices;
126 m_RecurrenceChoice_choices.Add( _W("None") );
127 m_RecurrenceChoice_choices.Add( _W("Daily") );
128 m_RecurrenceChoice_choices.Add( _W("Weekly") );
129 m_RecurrenceChoice_choices.Add( _W("Monthly") );
130 m_RecurrenceChoice_choices.Add( _W("Yearly") );
132 m_RecurrenceChoice = new wxChoice(this, Dialog_TaskEdit_RecurrenceChoice, wxDefaultPosition, wxDefaultSize, m_RecurrenceChoice_choices, 0);
133 RecurIntervalLabel = new wxStaticText(this, wxID_ANY, _W("Interval:"));
134 RecurIntervalLabelB = new wxStaticText(this, wxID_ANY, _W("Every"));
135 m_IntervalSpinner = new wxSpinCtrl(this, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999);
136 m_IntervalUnitLabel = new wxStaticText(this, wxID_ANY, _W("days? weeks? months?"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
137 RecurDaysLabel = new wxStaticText(this, wxID_ANY, _W("Days:"));
138 m_SunCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
139 m_MonCheck = new wxCheckBox(this, wxID_ANY, wxT("M"));
140 m_TueCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
141 m_WedCheck = new wxCheckBox(this, wxID_ANY, wxT("W"));
142 m_ThuCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
143 m_FriCheck = new wxCheckBox(this, wxID_ANY, wxT("F"));
144 m_SatCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
145 RecurRelativeDateLabel = new wxStaticText(this, wxID_ANY, _W("Relative Date:"));
146 m_RelativeDateCheck = new wxCheckBox(this, wxID_ANY, wxEmptyString);
147 RecurEndDateLabel = new wxStaticText(this, wxID_ANY, _W("End Date:"));
148 m_NeverEndsCheck = new wxCheckBox(this, Dialog_TaskEdit_NeverEndsCheck, _W("Never ends"));
149 m_RecurEndDateCtrl = new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
150 static_line_3 = new wxStaticLine(this, wxID_ANY);
151 label_4 = new wxStaticText(this, wxID_ANY, _W("Categories:"));
152 m_CategoriesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
153 label_3 = new wxStaticText(this, wxID_ANY, _W("Notes:"));
154 m_NotesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
156 set_properties();
157 do_layout();
158 // end wxGlade
160 m_top_sizer->Add(bottom_buttons, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5);
162 // fill the time zone control with real time zones
163 m_TimezoneChoice->Clear();
164 m_TimezoneChoice->Append(_W("Assume Local Timezone"), (void*)0);
165 Barry::TimeZones::const_iterator b, e;
166 for( b = m_zones->begin(), e = m_zones->end(); b != e; ++b ) {
167 m_TimezoneChoice->Append(
168 wxString(b->GetDescription().c_str(), wxConvUTF8),
169 (void*) &b->Index);
171 m_TimezoneChoice->SetSelection(0);
173 // layout again, in case sizes are different
174 RedoLayout();
177 void TaskEditDlg::RedoLayout()
179 m_top_sizer->Fit(this);
180 Layout();
184 BEGIN_EVENT_TABLE(TaskEditDlg, wxDialog)
185 // begin wxGlade: TaskEditDlg::event_table
186 EVT_CHECKBOX(Dialog_TaskEdit_DueCheck, TaskEditDlg::OnDueCheck)
187 EVT_CHECKBOX(Dialog_TaskEdit_ReminderCheck, TaskEditDlg::OnReminderCheck)
188 EVT_CHOICE(Dialog_TaskEdit_RecurrenceChoice, TaskEditDlg::OnRecurrenceChoice)
189 EVT_CHECKBOX(Dialog_TaskEdit_NeverEndsCheck, TaskEditDlg::OnEndDateCheckbox)
190 // end wxGlade
191 END_EVENT_TABLE();
194 // wxGlade: add TaskEditDlg event handlers
196 void TaskEditDlg::OnDueCheck(wxCommandEvent &event)
198 EnableDueDate(m_DueCheck->IsChecked());
200 // make sure the first date is in a recent range, if not previously
201 // valid...
202 MakeDateRecent(m_DueCheck->IsChecked(), m_DueDateCtrl);
205 void TaskEditDlg::OnRecurrenceChoice(wxCommandEvent &event)
207 TransferDataFromWindow();
208 EnableRecurMode(m_rec.Recurring);
211 void TaskEditDlg::OnEndDateCheckbox(wxCommandEvent &event)
213 m_RecurEndDateCtrl->Enable( !m_NeverEndsCheck->IsChecked() );
215 // make sure there is a recent date in the ctrl
216 MakeDateRecent(!m_NeverEndsCheck->IsChecked(), m_RecurEndDateCtrl);
219 void TaskEditDlg::OnReminderCheck(wxCommandEvent &event)
221 EnableReminderDate(m_ReminderCheck->IsChecked());
223 // make sure the first date is in a recent range, if not previously
224 // valid...
225 MakeDateRecent(m_ReminderCheck->IsChecked(), m_ReminderDateCtrl);
228 void TaskEditDlg::set_properties()
230 // begin wxGlade: TaskEditDlg::set_properties
231 SetTitle(_W("Task Event"));
232 m_TaskSummary->SetFocus();
233 m_TaskSummary->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Summary)));
234 m_StatusChoice->SetSelection(0);
235 m_PriorityChoice->SetSelection(1);
236 m_DueDateCtrl->SetMinSize(wxSize(110, -1));
237 m_DueDateCtrl->SetValidator(DateTimeValidator(&m_DueDateObj.m_date));
238 m_DueHoursSpinner->SetMinSize(wxSize(45, -1));
239 m_DueHoursSpinner->SetValidator(wxGenericValidator(&m_DueDateObj.m_hour));
240 m_DueMinutesSpinner->SetMinSize(wxSize(45, -1));
241 m_DueMinutesSpinner->SetValidator(wxGenericValidator(&m_DueDateObj.m_min));
242 m_TimezoneChoice->SetSelection(0);
243 m_ReminderDateCtrl->SetMinSize(wxSize(110, -1));
244 m_ReminderDateCtrl->SetValidator(DateTimeValidator(&m_ReminderDateObj.m_date));
245 m_ReminderHoursSpinner->SetMinSize(wxSize(45, -1));
246 m_ReminderHoursSpinner->SetToolTip(_W("Set Reminder to 0 to disable"));
247 m_ReminderHoursSpinner->SetValidator(wxGenericValidator(&m_ReminderDateObj.m_hour));
248 m_ReminderMinutesSpinner->SetMinSize(wxSize(45, -1));
249 m_ReminderMinutesSpinner->SetToolTip(_W("Set Reminder to 0 to disable"));
250 m_ReminderMinutesSpinner->SetValidator(wxGenericValidator(&m_ReminderDateObj.m_min));
251 m_RecurrenceChoice->SetValidator(wxGenericValidator(&m_recur_choice));
252 m_RecurrenceChoice->SetSelection(0);
253 m_IntervalSpinner->SetMinSize(wxSize(45, -1));
254 m_IntervalSpinner->SetValidator(wxGenericValidator(&m_interval));
255 m_SunCheck->SetValidator(wxGenericValidator(&m_weekdays[0]));
256 m_MonCheck->SetValidator(wxGenericValidator(&m_weekdays[1]));
257 m_TueCheck->SetValidator(wxGenericValidator(&m_weekdays[2]));
258 m_WedCheck->SetValidator(wxGenericValidator(&m_weekdays[3]));
259 m_ThuCheck->SetValidator(wxGenericValidator(&m_weekdays[4]));
260 m_FriCheck->SetValidator(wxGenericValidator(&m_weekdays[5]));
261 m_SatCheck->SetValidator(wxGenericValidator(&m_weekdays[6]));
262 RecurRelativeDateLabel->SetToolTip(_W("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
263 m_RelativeDateCheck->SetToolTip(_W("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
264 m_RelativeDateCheck->SetValidator(wxGenericValidator(&m_relative_date));
265 m_NeverEndsCheck->SetValidator(wxGenericValidator(&m_rec.Perpetual));
266 m_NeverEndsCheck->SetValue(1);
267 m_RecurEndDateCtrl->SetMinSize(wxSize(110, -1));
268 m_RecurEndDateCtrl->Enable(false);
269 m_RecurEndDateCtrl->SetValidator(DateTimeValidator(&m_RecurEndDateObj.m_date));
270 m_CategoriesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_categories)));
271 m_NotesText->SetMinSize(wxSize(-1, 71));
272 m_NotesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Notes)));
273 // end wxGlade
276 void TaskEditDlg::do_layout()
278 // begin wxGlade: TaskEditDlg::do_layout
279 wxBoxSizer* sizer_surround = new wxBoxSizer(wxVERTICAL);
280 wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
281 wxFlexGridSizer* grid_sizer_3 = new wxFlexGridSizer(2, 2, 5, 5);
282 wxFlexGridSizer* grid_sizer_4 = new wxFlexGridSizer(5, 2, 5, 5);
283 wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
284 wxBoxSizer* m_DaysCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
285 wxBoxSizer* m_IntervalCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
286 wxFlexGridSizer* grid_sizer_2 = new wxFlexGridSizer(10, 2, 5, 5);
287 wxBoxSizer* sizer_5_copy = new wxBoxSizer(wxHORIZONTAL);
288 wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
289 wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer(2, 2, 5, 5);
290 grid_sizer_1->Add(label_1, 0, wxALIGN_CENTER_VERTICAL, 0);
291 grid_sizer_1->Add(m_TaskSummary, 0, wxEXPAND, 0);
292 grid_sizer_1->AddGrowableCol(1);
293 sizer_1->Add(grid_sizer_1, 0, wxEXPAND, 0);
294 sizer_1->Add(static_line_1, 0, wxALL|wxEXPAND, 5);
295 grid_sizer_2->Add(label_2, 0, wxALIGN_CENTER_VERTICAL, 0);
296 grid_sizer_2->Add(m_StatusChoice, 0, 0, 0);
297 grid_sizer_2->Add(label_9, 0, wxALIGN_CENTER_VERTICAL, 0);
298 grid_sizer_2->Add(m_PriorityChoice, 0, 0, 0);
299 grid_sizer_2->Add(label_5, 0, wxALIGN_CENTER_VERTICAL, 0);
300 sizer_3->Add(m_DueCheck, 0, 0, 0);
301 sizer_3->Add(m_DueDateCtrl, 0, 0, 0);
302 sizer_3->Add(20, 20, 0, 0, 0);
303 sizer_3->Add(m_DueHoursSpinner, 0, 0, 0);
304 sizer_3->Add(label_11, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
305 sizer_3->Add(m_DueMinutesSpinner, 0, 0, 0);
306 grid_sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
307 grid_sizer_2->Add(label_8, 0, wxALIGN_CENTER_VERTICAL, 0);
308 grid_sizer_2->Add(m_TimezoneChoice, 0, 0, 0);
309 grid_sizer_2->Add(label_10, 0, wxALIGN_CENTER_VERTICAL, 0);
310 sizer_5_copy->Add(m_ReminderCheck, 0, 0, 0);
311 sizer_5_copy->Add(m_ReminderDateCtrl, 0, 0, 0);
312 sizer_5_copy->Add(20, 20, 0, 0, 0);
313 sizer_5_copy->Add(m_ReminderHoursSpinner, 0, 0, 5);
314 sizer_5_copy->Add(label_6, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
315 sizer_5_copy->Add(m_ReminderMinutesSpinner, 0, wxRIGHT, 5);
316 grid_sizer_2->Add(sizer_5_copy, 1, wxEXPAND, 0);
317 grid_sizer_2->AddGrowableCol(1);
318 sizer_1->Add(grid_sizer_2, 0, wxEXPAND, 0);
319 sizer_1->Add(static_line_2, 0, wxALL|wxEXPAND, 5);
320 grid_sizer_4->Add(label_18, 0, wxALIGN_CENTER_VERTICAL, 0);
321 grid_sizer_4->Add(m_RecurrenceChoice, 0, 0, 0);
322 grid_sizer_4->Add(RecurIntervalLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
323 m_IntervalCtrlsSizer->Add(RecurIntervalLabelB, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
324 m_IntervalCtrlsSizer->Add(m_IntervalSpinner, 0, wxRIGHT, 5);
325 m_IntervalCtrlsSizer->Add(m_IntervalUnitLabel, 1, wxALIGN_CENTER_VERTICAL, 0);
326 grid_sizer_4->Add(m_IntervalCtrlsSizer, 1, wxEXPAND, 0);
327 grid_sizer_4->Add(RecurDaysLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
328 m_DaysCtrlsSizer->Add(m_SunCheck, 0, wxRIGHT, 5);
329 m_DaysCtrlsSizer->Add(m_MonCheck, 0, wxRIGHT, 5);
330 m_DaysCtrlsSizer->Add(m_TueCheck, 0, wxRIGHT, 5);
331 m_DaysCtrlsSizer->Add(m_WedCheck, 0, wxRIGHT, 5);
332 m_DaysCtrlsSizer->Add(m_ThuCheck, 0, wxRIGHT, 5);
333 m_DaysCtrlsSizer->Add(m_FriCheck, 0, wxRIGHT, 5);
334 m_DaysCtrlsSizer->Add(m_SatCheck, 0, wxRIGHT, 5);
335 grid_sizer_4->Add(m_DaysCtrlsSizer, 1, wxEXPAND, 0);
336 grid_sizer_4->Add(RecurRelativeDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
337 grid_sizer_4->Add(m_RelativeDateCheck, 0, 0, 0);
338 grid_sizer_4->Add(RecurEndDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
339 sizer_8->Add(m_NeverEndsCheck, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 10);
340 sizer_8->Add(m_RecurEndDateCtrl, 0, wxALIGN_CENTER_VERTICAL, 0);
341 grid_sizer_4->Add(sizer_8, 1, wxEXPAND, 0);
342 grid_sizer_4->AddGrowableCol(1);
343 sizer_1->Add(grid_sizer_4, 0, wxEXPAND, 0);
344 sizer_1->Add(static_line_3, 0, wxALL|wxEXPAND, 5);
345 grid_sizer_3->Add(label_4, 0, wxALIGN_CENTER_VERTICAL, 0);
346 grid_sizer_3->Add(m_CategoriesText, 0, wxEXPAND, 0);
347 grid_sizer_3->Add(label_3, 0, wxRIGHT, 5);
348 grid_sizer_3->Add(m_NotesText, 1, wxEXPAND, 0);
349 grid_sizer_3->AddGrowableCol(1);
350 sizer_1->Add(grid_sizer_3, 1, wxEXPAND, 0);
351 sizer_surround->Add(sizer_1, 1, wxALL|wxEXPAND, 10);
352 SetSizer(sizer_surround);
353 sizer_surround->Fit(this);
354 Layout();
355 // end wxGlade
357 m_top_sizer = sizer_surround;
360 bool TaskEditDlg::TransferDataToWindow()
362 // prepare temporary variables, from record
364 m_rec.Categories.CategoryList2Str(m_categories);
366 // due time
367 m_DueCheck->SetValue(m_rec.DueTime.IsValid());
368 EnableDueDate(m_rec.DueTime.IsValid());
369 m_DueDateObj.Set(m_rec.DueTime.Time);
371 // alarm / reminder time
372 m_ReminderCheck->SetValue(m_rec.AlarmTime.IsValid());
373 EnableReminderDate(m_rec.AlarmTime.IsValid());
374 m_ReminderDateObj.Set(m_rec.AlarmTime.Time);
376 // status
377 #define S_NOT_STARTED 0
378 #define S_IN_PROGRESS 1
379 #define S_COMPLETED 2
380 #define S_WAITING 3
381 #define S_DEFERRED 4
382 switch( m_rec.StatusFlag )
384 case Barry::Task::NotStarted:
385 default:
386 m_StatusChoice->SetSelection(S_NOT_STARTED);
387 break;
389 case Barry::Task::InProgress:
390 m_StatusChoice->SetSelection(S_IN_PROGRESS);
391 break;
393 case Barry::Task::Completed:
394 m_StatusChoice->SetSelection(S_COMPLETED);
395 break;
397 case Barry::Task::Waiting:
398 m_StatusChoice->SetSelection(S_WAITING);
399 break;
401 case Barry::Task::Deferred:
402 m_StatusChoice->SetSelection(S_DEFERRED);
403 break;
406 // priority
407 #define P_HIGH 0
408 #define P_NORMAL 1
409 #define P_LOW 2
410 switch( m_rec.PriorityFlag )
412 case Barry::Task::High:
413 m_PriorityChoice->SetSelection(P_HIGH);
414 break;
416 case Barry::Task::Normal:
417 default:
418 m_PriorityChoice->SetSelection(P_NORMAL);
419 break;
421 case Barry::Task::Low:
422 m_PriorityChoice->SetSelection(P_LOW);
423 break;
426 // set the timezone choice only if the record's data is valid
427 m_TimezoneChoice->SetSelection(0); // default to none
428 if( m_rec.TimeZoneValid ) {
429 TimeZones::const_iterator i = m_zones->Find(m_rec.TimeZoneCode);
430 if( i != m_zones->end() ) {
431 int array_index = i - m_zones->begin();
432 // select item, skipping 0's "none" option
433 m_TimezoneChoice->SetSelection(array_index + 1);
437 // Note that recur_choice values are (zero-based) in the following
438 // order:
439 // None, Daily, Weekly, Monthly, Yearly
440 #define RC_NONE 0
441 #define RC_DAILY 1
442 #define RC_WEEKLY 2
443 #define RC_MONTHLY 3
444 #define RC_YEARLY 4
446 if( m_rec.Recurring ) {
447 switch( m_rec.RecurringType )
449 case Barry::RecurBase::Day:
450 m_recur_choice = RC_DAILY;
451 m_relative_date = false;
452 break;
454 case Barry::RecurBase::MonthByDate:
455 m_recur_choice = RC_MONTHLY;
456 m_relative_date = false;
457 break;
459 case Barry::RecurBase::MonthByDay:
460 m_recur_choice = RC_MONTHLY;
461 m_relative_date = true;
462 break;
464 case Barry::RecurBase::YearByDate:
465 m_recur_choice = RC_YEARLY;
466 m_relative_date = false;
467 break;
469 case Barry::RecurBase::YearByDay:
470 m_recur_choice = RC_YEARLY;
471 m_relative_date = true;
472 break;
474 case Barry::RecurBase::Week:
475 m_recur_choice = RC_WEEKLY;
476 m_relative_date = false;
477 m_weekdays[0] = m_rec.WeekDays & CAL_WD_SUN;
478 m_weekdays[1] = m_rec.WeekDays & CAL_WD_MON;
479 m_weekdays[2] = m_rec.WeekDays & CAL_WD_TUE;
480 m_weekdays[3] = m_rec.WeekDays & CAL_WD_WED;
481 m_weekdays[4] = m_rec.WeekDays & CAL_WD_THU;
482 m_weekdays[5] = m_rec.WeekDays & CAL_WD_FRI;
483 m_weekdays[6] = m_rec.WeekDays & CAL_WD_SAT;
484 break;
486 default:
487 cerr << "Bad RecurringType in CalendarEditDlg" << endl;
488 m_recur_choice = RC_NONE;
489 m_relative_date = false;
492 else {
493 m_recur_choice = RC_NONE;
494 m_relative_date = false;
497 m_interval = m_rec.Interval;
499 m_RecurEndDateObj.Set(m_rec.RecurringEndTime.Time);
500 if( m_rec.Perpetual ) {
501 m_RecurEndDateCtrl->Enable(false);
503 else {
504 m_RecurEndDateCtrl->Enable();
507 EnableRecurMode(m_rec.Recurring);
509 m_strings.Refresh();
511 return wxDialog::TransferDataToWindow();
514 bool TaskEditDlg::TransferDataFromWindow()
516 if( !wxDialog::TransferDataFromWindow() )
517 return false;
519 m_strings.Sync();
521 m_rec.Categories.CategoryStr2List(m_categories);
523 // due time
524 if( m_DueCheck->IsChecked() )
525 m_rec.DueTime.Time = m_DueDateObj.Get();
526 else
527 m_rec.DueTime.clear();
529 // alarm / reminder time
530 if( m_ReminderCheck->IsChecked() )
531 m_rec.AlarmTime.Time = m_ReminderDateObj.Get();
532 else
533 m_rec.AlarmTime.clear();
535 // status
536 switch( m_StatusChoice->GetSelection() )
538 case S_NOT_STARTED:
539 default:
540 m_rec.StatusFlag = Barry::Task::NotStarted;
541 break;
543 case S_IN_PROGRESS:
544 m_rec.StatusFlag = Barry::Task::InProgress;
545 break;
547 case S_COMPLETED:
548 m_rec.StatusFlag = Barry::Task::Completed;
549 break;
551 case S_WAITING:
552 m_rec.StatusFlag = Barry::Task::Waiting;
553 break;
555 case S_DEFERRED:
556 m_rec.StatusFlag = Barry::Task::Deferred;
557 break;
560 // priority
561 switch( m_PriorityChoice->GetSelection() )
563 case P_HIGH:
564 m_rec.PriorityFlag = Barry::Task::High;
565 break;
567 case P_NORMAL:
568 default:
569 m_rec.PriorityFlag = Barry::Task::Normal;
570 break;
572 case P_LOW:
573 m_rec.PriorityFlag = Barry::Task::Low;
574 break;
577 // set the timezone choice only if the record's data is valid
578 int sel = m_TimezoneChoice->GetSelection();
579 if( sel > 0 ) {
580 m_rec.TimeZoneCode = (*m_zones)[sel-1].Index;
581 m_rec.TimeZoneValid = true;
583 else {
584 // default was selected
585 m_rec.TimeZoneValid = false;
588 // Note that recur_choice values are (zero-based) in the following
589 // order:
590 // None, Daily, Weekly, Monthly, Yearly
591 switch( m_recur_choice )
593 case RC_NONE:
594 default:
595 m_rec.Recurring = false;
596 break;
598 case RC_DAILY:
599 m_rec.Recurring = true;
600 m_rec.RecurringType = Barry::RecurBase::Day;
601 break;
603 case RC_WEEKLY:
604 m_rec.Recurring = true;
605 m_rec.RecurringType = Barry::RecurBase::Week;
606 m_rec.WeekDays = 0;
607 if( m_weekdays[0] ) m_rec.WeekDays |= CAL_WD_SUN;
608 if( m_weekdays[1] ) m_rec.WeekDays |= CAL_WD_MON;
609 if( m_weekdays[2] ) m_rec.WeekDays |= CAL_WD_TUE;
610 if( m_weekdays[3] ) m_rec.WeekDays |= CAL_WD_WED;
611 if( m_weekdays[4] ) m_rec.WeekDays |= CAL_WD_THU;
612 if( m_weekdays[5] ) m_rec.WeekDays |= CAL_WD_FRI;
613 if( m_weekdays[6] ) m_rec.WeekDays |= CAL_WD_SAT;
614 break;
616 case RC_MONTHLY:
617 m_rec.Recurring = true;
618 if( m_relative_date )
619 m_rec.RecurringType = Barry::RecurBase::MonthByDay;
620 else
621 m_rec.RecurringType = Barry::RecurBase::MonthByDate;
622 break;
624 case RC_YEARLY:
625 m_rec.Recurring = true;
626 if( m_relative_date )
627 m_rec.RecurringType = Barry::RecurBase::YearByDay;
628 else
629 m_rec.RecurringType = Barry::RecurBase::YearByDate;
630 break;
634 m_rec.Interval = m_interval;
636 if( !m_rec.Perpetual ) {
637 m_rec.RecurringEndTime.Time = m_RecurEndDateObj.Get();
640 cout << "TaskEditDlg::TransferDataFromWindow():\n" << m_rec << endl;
641 return true;
644 void TaskEditDlg::EnableDueDate(bool enable)
646 m_DueDateCtrl->Enable(enable);
647 m_DueHoursSpinner->Enable(enable);
648 m_DueMinutesSpinner->Enable(enable);
649 m_RecurrenceChoice->Enable(enable);
651 if( !enable ) {
652 m_RecurrenceChoice->SetSelection(0);
653 EnableRecurMode(false);
657 void TaskEditDlg::EnableReminderDate(bool enable)
659 m_ReminderDateCtrl->Enable(enable);
660 m_ReminderHoursSpinner->Enable(enable);
661 m_ReminderMinutesSpinner->Enable(enable);
664 void TaskEditDlg::EnableRecurMode(bool recur)
666 // show all controls
667 RecurIntervalLabel->Show(recur);
668 RecurIntervalLabelB->Show(recur);
669 m_IntervalSpinner->Show(recur);
670 m_IntervalUnitLabel->Show(recur);
671 RecurDaysLabel->Show(recur);
672 m_SunCheck->Show(recur);
673 m_MonCheck->Show(recur);
674 m_TueCheck->Show(recur);
675 m_WedCheck->Show(recur);
676 m_ThuCheck->Show(recur);
677 m_FriCheck->Show(recur);
678 m_SatCheck->Show(recur);
679 RecurRelativeDateLabel->Show(recur);
680 m_RelativeDateCheck->Show(recur);
681 RecurEndDateLabel->Show(recur);
682 m_NeverEndsCheck->Show(recur);
683 m_RecurEndDateCtrl->Show(recur);
685 // enable based on choice
686 int choice = m_RecurrenceChoice->GetSelection();
687 m_SunCheck->Enable(choice == RC_WEEKLY);
688 m_MonCheck->Enable(choice == RC_WEEKLY);
689 m_TueCheck->Enable(choice == RC_WEEKLY);
690 m_WedCheck->Enable(choice == RC_WEEKLY);
691 m_ThuCheck->Enable(choice == RC_WEEKLY);
692 m_FriCheck->Enable(choice == RC_WEEKLY);
693 m_SatCheck->Enable(choice == RC_WEEKLY);
695 // update labels
696 if( recur ) {
697 switch( m_RecurrenceChoice->GetSelection() )
699 case RC_NONE:
700 default:
701 m_IntervalUnitLabel->SetLabel(_T(""));
702 break;
704 case RC_DAILY:
705 m_IntervalUnitLabel->SetLabel(_W("day(s)"));
706 break;
708 case RC_WEEKLY:
709 m_IntervalUnitLabel->SetLabel(_W("week(s)"));
710 break;
712 case RC_MONTHLY:
713 m_IntervalUnitLabel->SetLabel(_W("month(s)"));
714 break;
716 case RC_YEARLY:
717 m_IntervalUnitLabel->SetLabel(_W("year(s)"));
718 break;
722 RedoLayout();
727 // Note: this file is very similar to CalendarEditDlg.cc, and should be kept
728 // in lock step as much as possible. They are in separate files, since
729 // the GUI code is generated with wxglade