desktop: CalEditDlg: added event handler changing interval field label
[barry.git] / desktop / src / CalendarEditDlg.cc
blobc8239bb756ce6c47621ca3982f377947f76381ba
1 ///
2 /// \file CalendarEditDlg.cc
3 /// Dialog class to handle the editing of the Calendar record
4 ///
6 /*
7 Copyright (C) 2012, 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 "CalendarEditDlg.h"
23 #include "windowids.h"
24 #include <wx/valgen.h>
25 #include "wxval.h"
27 using namespace std;
28 using namespace Barry;
30 // begin wxGlade: ::extracode
31 // end wxGlade
34 //////////////////////////////////////////////////////////////////////////////
35 // CalendarEditDlg class
37 CalendarEditDlg::CalendarEditDlg(wxWindow* parent,
38 Barry::Calendar &rec,
39 bool editable,
40 const Barry::TimeZones *device_zones)
41 : wxDialog(parent, Dialog_CalendarEdit, _T("Calendar Record"))
42 , m_zones(device_zones ? device_zones : &m_static_zones)
43 , m_rec(rec)
44 , m_duration_hours(0)
45 , m_duration_minutes(0)
46 , m_reminder_hours(0)
47 , m_reminder_minutes(0)
48 , m_interval(0)
49 , m_relative_date(false)
51 // set all weekday 'bits' to false
52 for( int i = 0; i < 7; i++ )
53 m_weekdays[i] = false;
55 if( editable ) {
56 bottom_buttons = CreateButtonSizer(wxOK | wxCANCEL);
58 else {
59 bottom_buttons = CreateButtonSizer(wxCANCEL);
62 // begin wxGlade: CalendarEditDlg::CalendarEditDlg
63 label_1 = new wxStaticText(this, wxID_ANY, wxT("Subject:"));
64 m_Subject = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
65 label_2 = new wxStaticText(this, wxID_ANY, wxT("Location:"));
66 m_Location = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
67 static_line_1 = new wxStaticLine(this, wxID_ANY);
68 label_4 = new wxStaticText(this, wxID_ANY, wxT("All Day Event:"));
69 m_AllDayCheck = new wxCheckBox(this, Dialog_CalendarEdit_AllDayCheck, wxEmptyString);
70 label_5 = new wxStaticText(this, wxID_ANY, wxT("Start:"));
71 m_StartDateCtrl = new wxDatePickerCtrl(this, Dialog_CalendarEdit_StartDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
72 m_StartHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_StartHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
73 label_11 = new wxStaticText(this, wxID_ANY, wxT(":"));
74 m_StartMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_StartMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
75 label_6 = new wxStaticText(this, wxID_ANY, wxT("End:"));
76 m_EndDateCtrl = new wxDatePickerCtrl(this, Dialog_CalendarEdit_EndDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
77 m_EndHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_EndHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
78 label_12 = new wxStaticText(this, wxID_ANY, wxT(":"));
79 m_EndMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_EndMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
80 label_7 = new wxStaticText(this, wxID_ANY, wxT("Duration:"));
81 m_DurationHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_DurationHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
82 label_13 = new wxStaticText(this, wxID_ANY, wxT("hours and"));
83 m_DurationMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_DurationMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
84 label_17 = new wxStaticText(this, wxID_ANY, wxT("minutes."));
85 label_8 = new wxStaticText(this, wxID_ANY, wxT("Time Zone:"));
86 const wxString m_TimezoneChoice_choices[] = {
87 wxT("System Time Zone")
89 m_TimezoneChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 1, m_TimezoneChoice_choices, 0);
90 label_9 = new wxStaticText(this, wxID_ANY, wxT("Show As:"));
91 const wxString m_ShowAsChoice_choices[] = {
92 wxT("Free"),
93 wxT("Tentative"),
94 wxT("Busy"),
95 wxT("Out of Office")
97 m_ShowAsChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, m_ShowAsChoice_choices, 0);
98 label_10 = new wxStaticText(this, wxID_ANY, wxT("Reminder:"));
99 m_ReminderHoursSpinner = new wxSpinCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
100 label_13_copy = new wxStaticText(this, wxID_ANY, wxT("hours and"));
101 m_ReminderMinutesSpinner = new wxSpinCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
102 label_17_copy = new wxStaticText(this, wxID_ANY, wxT("minutes."));
103 static_line_2 = new wxStaticLine(this, wxID_ANY);
104 label_18 = new wxStaticText(this, wxID_ANY, wxT("Recurrence:"));
105 const wxString m_RecurrenceChoice_choices[] = {
106 wxT("None"),
107 wxT("Daily"),
108 wxT("Weekly"),
109 wxT("Monthly"),
110 wxT("Yearly")
112 m_RecurrenceChoice = new wxChoice(this, Dialog_CalendarEdit_RecurrenceChoice, wxDefaultPosition, wxDefaultSize, 5, m_RecurrenceChoice_choices, 0);
113 RecurIntervalLabel = new wxStaticText(this, wxID_ANY, wxT("Interval:"));
114 RecurIntervalLabelB = new wxStaticText(this, wxID_ANY, wxT("Every"));
115 m_IntervalSpinner = new wxSpinCtrl(this, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999);
116 m_IntervalUnitLabel = new wxStaticText(this, wxID_ANY, wxT("days? weeks? months?"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
117 RecurDaysLabel = new wxStaticText(this, wxID_ANY, wxT("Days:"));
118 m_SunCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
119 m_MonCheck = new wxCheckBox(this, wxID_ANY, wxT("M"));
120 m_TueCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
121 m_WedCheck = new wxCheckBox(this, wxID_ANY, wxT("W"));
122 m_ThuCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
123 m_FriCheck = new wxCheckBox(this, wxID_ANY, wxT("F"));
124 m_SatCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
125 RecurRelativeDateLabel = new wxStaticText(this, wxID_ANY, wxT("Relative Date:"));
126 m_RelativeDateCheck = new wxCheckBox(this, wxID_ANY, wxEmptyString);
127 RecurEndDateLabel = new wxStaticText(this, wxID_ANY, wxT("End Date:"));
128 m_NeverEndsCheck = new wxCheckBox(this, Dialog_CalendarEdit_NeverEndsCheck, wxT("Never ends"));
129 m_RecurEndDateCtrl = new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
130 static_line_3 = new wxStaticLine(this, wxID_ANY);
131 label_14 = new wxStaticText(this, wxID_ANY, wxT("Organizer:"));
132 m_OrganizerText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
133 label_15 = new wxStaticText(this, wxID_ANY, wxT("Invited:"));
134 m_InvitedText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
135 label_16 = new wxStaticText(this, wxID_ANY, wxT("Accepted By:"));
136 m_AcceptedByText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
137 static_line_4 = new wxStaticLine(this, wxID_ANY);
138 const wxString m_ClassRadioBox_choices[] = {
139 wxT("Public"),
140 wxT("Private"),
141 wxT("Confidential")
143 m_ClassRadioBox = new wxRadioBox(this, wxID_ANY, wxT("Class"), wxDefaultPosition, wxDefaultSize, 3, m_ClassRadioBox_choices, 3, wxRA_SPECIFY_COLS);
144 static_line_5 = new wxStaticLine(this, wxID_ANY);
145 label_3 = new wxStaticText(this, wxID_ANY, wxT("Notes:"));
146 m_NotesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
148 set_properties();
149 do_layout();
150 // end wxGlade
152 m_top_sizer->Add(bottom_buttons, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5);
154 // fill the time zone control with real time zones
155 m_TimezoneChoice->Clear();
156 m_TimezoneChoice->Append(wxT("Assume Local Timezone"), (void*)0);
157 Barry::TimeZones::const_iterator b, e;
158 for( b = m_zones->begin(), e = m_zones->end(); b != e; ++b ) {
159 m_TimezoneChoice->Append(
160 wxString(b->GetDescription().c_str(), wxConvUTF8),
161 (void*) &b->Index);
163 m_TimezoneChoice->SetSelection(0);
165 // layout again, in case sizes are different
166 RedoLayout();
169 void CalendarEditDlg::RedoLayout()
171 m_top_sizer->Fit(this);
172 Layout();
175 BEGIN_EVENT_TABLE(CalendarEditDlg, wxDialog)
176 // begin wxGlade: CalendarEditDlg::event_table
177 EVT_CHECKBOX(Dialog_CalendarEdit_AllDayCheck, CalendarEditDlg::OnAllDayEvent)
178 EVT_DATE_CHANGED(Dialog_CalendarEdit_StartDateCtrl, CalendarEditDlg::OnStartDateChanged)
179 EVT_SPINCTRL(Dialog_CalendarEdit_StartHoursSpinner, CalendarEditDlg::OnStartHoursSpin)
180 EVT_SPINCTRL(Dialog_CalendarEdit_StartMinutesSpinner, CalendarEditDlg::OnStartMinutesSpin)
181 EVT_DATE_CHANGED(Dialog_CalendarEdit_EndDateCtrl, CalendarEditDlg::OnEndDateChanged)
182 EVT_SPINCTRL(Dialog_CalendarEdit_EndHoursSpinner, CalendarEditDlg::OnEndHoursSpin)
183 EVT_SPINCTRL(Dialog_CalendarEdit_EndMinutesSpinner, CalendarEditDlg::OnEndMinutesSpin)
184 EVT_SPINCTRL(Dialog_CalendarEdit_DurationHoursSpinner, CalendarEditDlg::OnDurationHoursSpin)
185 EVT_SPINCTRL(Dialog_CalendarEdit_DurationMinutesSpinner, CalendarEditDlg::OnDurationMinutesSpin)
186 EVT_CHOICE(Dialog_CalendarEdit_RecurrenceChoice, CalendarEditDlg::OnRecurrenceChoice)
187 EVT_CHECKBOX(Dialog_CalendarEdit_NeverEndsCheck, CalendarEditDlg::OnEndDateCheckbox)
188 // end wxGlade
189 END_EVENT_TABLE();
192 void CalendarEditDlg::OnAllDayEvent(wxCommandEvent &event)
194 bool checked = m_AllDayCheck->IsChecked();
196 if( checked ) {
197 // set start time to date at 00:00 and end time at
198 // day + 1 at 00:00
200 // time
201 m_StartHoursSpinner->SetValue(0);
202 m_StartMinutesSpinner->SetValue(0);
203 m_EndHoursSpinner->SetValue(0);
204 m_EndMinutesSpinner->SetValue(0);
206 // date
207 m_StartDateCtrl->SetValue(m_StartDateCtrl->GetValue().GetDateOnly());
208 m_EndDateCtrl->SetValue(m_StartDateCtrl->GetValue().GetDateOnly() + wxDateSpan::Day());
210 // duration
211 m_DurationHoursSpinner->SetValue(24);
212 m_DurationMinutesSpinner->SetValue(0);
215 EnableAllDayMode(checked);
218 void CalendarEditDlg::OnStartDateChanged(wxDateEvent &event)
220 UpdateDuration();
223 void CalendarEditDlg::OnStartHoursSpin(wxSpinEvent &event)
225 UpdateDuration();
228 void CalendarEditDlg::OnStartMinutesSpin(wxSpinEvent &event)
230 UpdateDuration();
233 void CalendarEditDlg::OnEndDateChanged(wxDateEvent &event)
235 UpdateDuration();
238 void CalendarEditDlg::OnEndHoursSpin(wxSpinEvent &event)
240 UpdateDuration();
243 void CalendarEditDlg::OnEndMinutesSpin(wxSpinEvent &event)
245 UpdateDuration();
248 void CalendarEditDlg::OnDurationHoursSpin(wxSpinEvent &event)
250 UpdateEndDate();
253 void CalendarEditDlg::OnDurationMinutesSpin(wxSpinEvent &event)
255 UpdateEndDate();
258 void CalendarEditDlg::OnRecurrenceChoice(wxCommandEvent &event)
260 TransferDataFromWindow();
261 EnableRecurMode(m_rec.Recurring);
265 void CalendarEditDlg::OnEndDateCheckbox(wxCommandEvent &event)
267 m_RecurEndDateCtrl->Enable( !m_NeverEndsCheck->IsChecked() );
271 // wxGlade: add CalendarEditDlg event handlers
274 void CalendarEditDlg::set_properties()
276 // begin wxGlade: CalendarEditDlg::set_properties
277 SetTitle(wxT("Calendar Event"));
278 m_Subject->SetFocus();
279 m_Subject->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Subject)));
280 m_Location->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Location)));
281 m_AllDayCheck->SetValidator(wxGenericValidator(&m_rec.AllDayEvent));
282 m_StartDateCtrl->SetMinSize(wxSize(110, -1));
283 m_StartDateCtrl->SetValidator(DateTimeValidator(&m_StartDateObj.m_date));
284 m_StartHoursSpinner->SetMinSize(wxSize(45, -1));
285 m_StartHoursSpinner->SetValidator(wxGenericValidator(&m_StartDateObj.m_hour));
286 m_StartMinutesSpinner->SetMinSize(wxSize(45, -1));
287 m_StartMinutesSpinner->SetValidator(wxGenericValidator(&m_StartDateObj.m_min));
288 m_EndDateCtrl->SetMinSize(wxSize(110, -1));
289 m_EndDateCtrl->SetValidator(DateTimeValidator(&m_EndDateObj.m_date));
290 m_EndHoursSpinner->SetMinSize(wxSize(45, -1));
291 m_EndHoursSpinner->SetValidator(wxGenericValidator(&m_EndDateObj.m_hour));
292 m_EndMinutesSpinner->SetMinSize(wxSize(45, -1));
293 m_EndMinutesSpinner->SetValidator(wxGenericValidator(&m_EndDateObj.m_min));
294 m_DurationHoursSpinner->SetMinSize(wxSize(45, -1));
295 m_DurationHoursSpinner->SetValidator(wxGenericValidator(&m_duration_hours));
296 m_DurationMinutesSpinner->SetMinSize(wxSize(45, -1));
297 m_DurationMinutesSpinner->SetValidator(wxGenericValidator(&m_duration_minutes));
298 m_TimezoneChoice->SetSelection(0);
299 m_ShowAsChoice->SetSelection(2);
300 m_ReminderHoursSpinner->SetMinSize(wxSize(45, -1));
301 m_ReminderHoursSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
302 m_ReminderHoursSpinner->SetValidator(wxGenericValidator(&m_reminder_hours));
303 m_ReminderMinutesSpinner->SetMinSize(wxSize(45, -1));
304 m_ReminderMinutesSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
305 m_ReminderMinutesSpinner->SetValidator(wxGenericValidator(&m_reminder_minutes));
306 m_RecurrenceChoice->SetValidator(wxGenericValidator(&m_recur_choice));
307 m_RecurrenceChoice->SetSelection(0);
308 m_IntervalSpinner->SetMinSize(wxSize(45, -1));
309 m_IntervalSpinner->SetValidator(wxGenericValidator(&m_interval));
310 m_SunCheck->SetValidator(wxGenericValidator(&m_weekdays[0]));
311 m_MonCheck->SetValidator(wxGenericValidator(&m_weekdays[1]));
312 m_TueCheck->SetValidator(wxGenericValidator(&m_weekdays[2]));
313 m_WedCheck->SetValidator(wxGenericValidator(&m_weekdays[3]));
314 m_ThuCheck->SetValidator(wxGenericValidator(&m_weekdays[4]));
315 m_FriCheck->SetValidator(wxGenericValidator(&m_weekdays[5]));
316 m_SatCheck->SetValidator(wxGenericValidator(&m_weekdays[6]));
317 RecurRelativeDateLabel->SetToolTip(wxT("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
318 m_RelativeDateCheck->SetToolTip(wxT("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
319 m_RelativeDateCheck->SetValidator(wxGenericValidator(&m_relative_date));
320 m_NeverEndsCheck->SetValidator(wxGenericValidator(&m_rec.Perpetual));
321 m_NeverEndsCheck->SetValue(1);
322 m_RecurEndDateCtrl->SetMinSize(wxSize(110, -1));
323 m_RecurEndDateCtrl->Enable(false);
324 m_RecurEndDateCtrl->SetValidator(DateTimeValidator(&m_RecurEndDateObj.m_date));
325 m_OrganizerText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_organizer)));
326 m_InvitedText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_invited)));
327 m_AcceptedByText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_accepted_by)));
328 m_ClassRadioBox->SetValidator(MakeRadioBoxValidator(&m_rec.ClassFlag).Add(Barry::Calendar::Public).Add(Barry::Calendar::Private).Add(Barry::Calendar::Confidential));
329 m_ClassRadioBox->SetSelection(0);
330 m_NotesText->SetMinSize(wxSize(-1, 61));
331 m_NotesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Notes)));
332 // end wxGlade
336 void CalendarEditDlg::do_layout()
338 // begin wxGlade: CalendarEditDlg::do_layout
339 wxBoxSizer* sizer_surround = new wxBoxSizer(wxVERTICAL);
340 wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
341 wxBoxSizer* sizer_2 = new wxBoxSizer(wxHORIZONTAL);
342 wxFlexGridSizer* grid_sizer_3 = new wxFlexGridSizer(3, 2, 5, 5);
343 wxFlexGridSizer* grid_sizer_4 = new wxFlexGridSizer(5, 2, 5, 5);
344 wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
345 wxBoxSizer* m_DaysCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
346 wxBoxSizer* m_IntervalCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
347 wxFlexGridSizer* grid_sizer_2 = new wxFlexGridSizer(7, 2, 5, 5);
348 wxBoxSizer* sizer_5_copy = new wxBoxSizer(wxHORIZONTAL);
349 wxBoxSizer* sizer_5 = new wxBoxSizer(wxHORIZONTAL);
350 wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
351 wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
352 wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer(2, 2, 5, 5);
353 grid_sizer_1->Add(label_1, 0, 0, 0);
354 grid_sizer_1->Add(m_Subject, 0, wxEXPAND, 0);
355 grid_sizer_1->Add(label_2, 0, 0, 0);
356 grid_sizer_1->Add(m_Location, 0, wxEXPAND, 0);
357 grid_sizer_1->AddGrowableCol(1);
358 sizer_1->Add(grid_sizer_1, 0, wxEXPAND, 0);
359 sizer_1->Add(static_line_1, 0, wxALL|wxEXPAND, 5);
360 grid_sizer_2->Add(label_4, 0, 0, 0);
361 grid_sizer_2->Add(m_AllDayCheck, 0, 0, 0);
362 grid_sizer_2->Add(label_5, 0, wxALIGN_CENTER_VERTICAL, 0);
363 sizer_3->Add(m_StartDateCtrl, 0, 0, 0);
364 sizer_3->Add(20, 20, 0, 0, 0);
365 sizer_3->Add(m_StartHoursSpinner, 0, 0, 0);
366 sizer_3->Add(label_11, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
367 sizer_3->Add(m_StartMinutesSpinner, 0, 0, 0);
368 grid_sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
369 grid_sizer_2->Add(label_6, 0, wxALIGN_CENTER_VERTICAL, 0);
370 sizer_4->Add(m_EndDateCtrl, 0, 0, 0);
371 sizer_4->Add(20, 20, 0, 0, 0);
372 sizer_4->Add(m_EndHoursSpinner, 0, 0, 0);
373 sizer_4->Add(label_12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 1);
374 sizer_4->Add(m_EndMinutesSpinner, 0, 0, 0);
375 grid_sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
376 grid_sizer_2->Add(label_7, 0, wxALIGN_CENTER_VERTICAL, 0);
377 sizer_5->Add(m_DurationHoursSpinner, 0, wxRIGHT, 5);
378 sizer_5->Add(label_13, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
379 sizer_5->Add(m_DurationMinutesSpinner, 0, wxRIGHT, 5);
380 sizer_5->Add(label_17, 0, wxALIGN_CENTER_VERTICAL, 0);
381 grid_sizer_2->Add(sizer_5, 1, wxEXPAND, 0);
382 grid_sizer_2->Add(label_8, 0, wxALIGN_CENTER_VERTICAL, 0);
383 grid_sizer_2->Add(m_TimezoneChoice, 0, 0, 0);
384 grid_sizer_2->Add(label_9, 0, wxALIGN_CENTER_VERTICAL, 0);
385 grid_sizer_2->Add(m_ShowAsChoice, 0, 0, 0);
386 grid_sizer_2->Add(label_10, 0, wxALIGN_CENTER_VERTICAL, 0);
387 sizer_5_copy->Add(m_ReminderHoursSpinner, 0, wxRIGHT, 5);
388 sizer_5_copy->Add(label_13_copy, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
389 sizer_5_copy->Add(m_ReminderMinutesSpinner, 0, wxRIGHT, 5);
390 sizer_5_copy->Add(label_17_copy, 0, wxALIGN_CENTER_VERTICAL, 0);
391 grid_sizer_2->Add(sizer_5_copy, 1, wxEXPAND, 0);
392 grid_sizer_2->AddGrowableCol(1);
393 sizer_1->Add(grid_sizer_2, 0, wxEXPAND, 0);
394 sizer_1->Add(static_line_2, 0, wxALL|wxEXPAND, 5);
395 grid_sizer_4->Add(label_18, 0, wxALIGN_CENTER_VERTICAL, 0);
396 grid_sizer_4->Add(m_RecurrenceChoice, 0, 0, 0);
397 grid_sizer_4->Add(RecurIntervalLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
398 m_IntervalCtrlsSizer->Add(RecurIntervalLabelB, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
399 m_IntervalCtrlsSizer->Add(m_IntervalSpinner, 0, wxRIGHT, 5);
400 m_IntervalCtrlsSizer->Add(m_IntervalUnitLabel, 1, wxALIGN_CENTER_VERTICAL, 0);
401 grid_sizer_4->Add(m_IntervalCtrlsSizer, 1, wxEXPAND, 0);
402 grid_sizer_4->Add(RecurDaysLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
403 m_DaysCtrlsSizer->Add(m_SunCheck, 0, wxRIGHT, 5);
404 m_DaysCtrlsSizer->Add(m_MonCheck, 0, wxRIGHT, 5);
405 m_DaysCtrlsSizer->Add(m_TueCheck, 0, wxRIGHT, 5);
406 m_DaysCtrlsSizer->Add(m_WedCheck, 0, wxRIGHT, 5);
407 m_DaysCtrlsSizer->Add(m_ThuCheck, 0, wxRIGHT, 5);
408 m_DaysCtrlsSizer->Add(m_FriCheck, 0, wxRIGHT, 5);
409 m_DaysCtrlsSizer->Add(m_SatCheck, 0, wxRIGHT, 5);
410 grid_sizer_4->Add(m_DaysCtrlsSizer, 1, wxEXPAND, 0);
411 grid_sizer_4->Add(RecurRelativeDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
412 grid_sizer_4->Add(m_RelativeDateCheck, 0, 0, 0);
413 grid_sizer_4->Add(RecurEndDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
414 sizer_8->Add(m_NeverEndsCheck, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 10);
415 sizer_8->Add(m_RecurEndDateCtrl, 0, wxALIGN_CENTER_VERTICAL, 0);
416 grid_sizer_4->Add(sizer_8, 1, wxEXPAND, 0);
417 grid_sizer_4->AddGrowableCol(1);
418 sizer_1->Add(grid_sizer_4, 0, wxEXPAND, 0);
419 sizer_1->Add(static_line_3, 0, wxALL|wxEXPAND, 5);
420 grid_sizer_3->Add(label_14, 0, wxALIGN_CENTER_VERTICAL, 0);
421 grid_sizer_3->Add(m_OrganizerText, 0, wxEXPAND, 0);
422 grid_sizer_3->Add(label_15, 0, wxALIGN_CENTER_VERTICAL, 0);
423 grid_sizer_3->Add(m_InvitedText, 0, wxEXPAND, 0);
424 grid_sizer_3->Add(label_16, 0, wxALIGN_CENTER_VERTICAL, 0);
425 grid_sizer_3->Add(m_AcceptedByText, 0, wxEXPAND, 0);
426 grid_sizer_3->AddGrowableCol(1);
427 sizer_1->Add(grid_sizer_3, 0, wxEXPAND, 0);
428 sizer_1->Add(static_line_4, 0, wxALL|wxEXPAND, 5);
429 sizer_1->Add(m_ClassRadioBox, 0, wxEXPAND, 0);
430 sizer_1->Add(static_line_5, 0, wxALL|wxEXPAND, 5);
431 sizer_2->Add(label_3, 0, wxRIGHT, 5);
432 sizer_2->Add(m_NotesText, 1, wxEXPAND, 0);
433 sizer_1->Add(sizer_2, 1, wxEXPAND, 0);
434 sizer_surround->Add(sizer_1, 1, wxALL|wxEXPAND, 10);
435 SetSizer(sizer_surround);
436 sizer_surround->Fit(this);
437 Layout();
438 // end wxGlade
440 m_top_sizer = sizer_surround;
443 bool CalendarEditDlg::TransferDataToWindow()
445 // prepare temporary variables, from record
447 m_organizer = m_rec.Organizer.ToCommaSeparated();
448 m_invited = m_rec.Invited.ToCommaSeparated();
449 m_accepted_by = m_rec.AcceptedBy.ToCommaSeparated();
451 m_StartDateObj.Set(m_rec.StartTime.Time);
452 m_EndDateObj.Set(m_rec.EndTime.Time);
454 int duration = m_rec.EndTime.Time - m_rec.StartTime.Time;
455 duration /= 60; // convert to minutes
456 if( m_rec.EndTime.Time >= m_rec.StartTime.Time ) {
457 m_duration_hours = duration / 60;
458 m_duration_minutes = duration % 60;
461 if( m_rec.NotificationTime.Time ) {
462 int span = m_rec.StartTime.Time - m_rec.NotificationTime.Time;
463 span /= 60; // convert to minutes
464 if( m_rec.StartTime.Time > m_rec.NotificationTime.Time ) {
465 m_reminder_hours = span / 60;
466 m_reminder_minutes = span % 60;
468 else {
469 m_reminder_hours = 0;
470 m_reminder_minutes = 15;
474 EnableAllDayMode(m_rec.AllDayEvent);
476 // set the timezone choice only if the record's data is valid
477 m_TimezoneChoice->SetSelection(0); // default to none
478 if( m_rec.TimeZoneValid ) {
479 TimeZones::const_iterator i = m_zones->Find(m_rec.TimeZoneCode);
480 if( i != m_zones->end() ) {
481 int array_index = i - m_zones->begin();
482 // select item, skipping 0's "none" option
483 m_TimezoneChoice->SetSelection(array_index + 1);
487 #define SA_FREE 0
488 #define SA_TENTATIVE 1
489 #define SA_BUSY 2
490 #define SA_OUT_OF_OFFICE 3
491 switch( m_rec.FreeBusyFlag )
493 case Barry::Calendar::Free:
494 m_ShowAsChoice->SetSelection(SA_FREE);
495 break;
497 case Barry::Calendar::Tentative:
498 m_ShowAsChoice->SetSelection(SA_TENTATIVE);
499 break;
501 case Barry::Calendar::Busy:
502 default:
503 m_ShowAsChoice->SetSelection(SA_BUSY);
504 break;
506 case Barry::Calendar::OutOfOffice:
507 m_ShowAsChoice->SetSelection(SA_OUT_OF_OFFICE);
508 break;
511 // Note that recur_choice values are (zero-based) in the following
512 // order:
513 // None, Daily, Weekly, Monthly, Yearly
514 #define RC_NONE 0
515 #define RC_DAILY 1
516 #define RC_WEEKLY 2
517 #define RC_MONTHLY 3
518 #define RC_YEARLY 4
520 if( m_rec.Recurring ) {
521 switch( m_rec.RecurringType )
523 case Barry::Calendar::Day:
524 m_recur_choice = RC_DAILY;
525 m_relative_date = false;
526 break;
528 case Barry::Calendar::MonthByDate:
529 m_recur_choice = RC_MONTHLY;
530 m_relative_date = false;
531 break;
533 case Barry::Calendar::MonthByDay:
534 m_recur_choice = RC_MONTHLY;
535 m_relative_date = true;
536 break;
538 case Barry::Calendar::YearByDate:
539 m_recur_choice = RC_YEARLY;
540 m_relative_date = false;
541 break;
543 case Barry::Calendar::YearByDay:
544 m_recur_choice = RC_YEARLY;
545 m_relative_date = true;
546 break;
548 case Barry::Calendar::Week:
549 m_recur_choice = RC_WEEKLY;
550 m_relative_date = false;
551 m_weekdays[0] = m_rec.WeekDays & CAL_WD_SUN;
552 m_weekdays[1] = m_rec.WeekDays & CAL_WD_MON;
553 m_weekdays[2] = m_rec.WeekDays & CAL_WD_TUE;
554 m_weekdays[3] = m_rec.WeekDays & CAL_WD_WED;
555 m_weekdays[4] = m_rec.WeekDays & CAL_WD_THU;
556 m_weekdays[5] = m_rec.WeekDays & CAL_WD_FRI;
557 m_weekdays[6] = m_rec.WeekDays & CAL_WD_SAT;
558 break;
560 default:
561 cerr << "Bad RecurringType in CalendarEditDlg" << endl;
562 m_recur_choice = RC_NONE;
563 m_relative_date = false;
566 else {
567 m_recur_choice = RC_NONE;
568 m_relative_date = false;
571 m_interval = m_rec.Interval;
573 if( m_rec.Perpetual ) {
574 m_RecurEndDateCtrl->Enable(false);
576 else {
577 m_RecurEndDateCtrl->Enable();
578 m_RecurEndDateObj.Set(m_rec.RecurringEndTime.Time);
581 EnableRecurMode(m_rec.Recurring);
583 m_strings.SyncToWx();
585 return wxDialog::TransferDataToWindow();
588 bool CalendarEditDlg::TransferDataFromWindow()
590 if( !wxDialog::TransferDataFromWindow() )
591 return false;
593 m_strings.SyncToStd();
595 m_rec.Organizer.clear();
596 m_rec.Organizer.AddCommaSeparated(m_organizer);
598 m_rec.Invited.clear();
599 m_rec.Invited.AddCommaSeparated(m_invited);
601 m_rec.AcceptedBy.clear();
602 m_rec.AcceptedBy.AddCommaSeparated(m_accepted_by);
604 m_rec.StartTime.Time = m_StartDateObj.Get();
605 m_rec.EndTime.Time = m_EndDateObj.Get();
606 if( m_rec.EndTime.Time < m_rec.StartTime.Time ) {
607 wxMessageBox(_T("Start time must come before end time."),
608 _T("Validation Error"), wxOK | wxICON_INFORMATION);
609 return false;
612 int span = ((m_reminder_hours * 60) + m_reminder_minutes) * 60;
613 m_rec.NotificationTime.Time = m_rec.StartTime.Time - span;
615 switch( m_ShowAsChoice->GetSelection() )
617 case SA_FREE:
618 m_rec.FreeBusyFlag = Barry::Calendar::Free;
619 break;
621 case SA_TENTATIVE:
622 m_rec.FreeBusyFlag = Barry::Calendar::Tentative;
623 break;
625 case SA_BUSY:
626 default:
627 m_rec.FreeBusyFlag = Barry::Calendar::Busy;
628 break;
630 case SA_OUT_OF_OFFICE:
631 m_rec.FreeBusyFlag = Barry::Calendar::OutOfOffice;
632 break;
635 // set the timezone choice only if the record's data is valid
636 int sel = m_TimezoneChoice->GetSelection();
637 if( sel > 0 ) {
638 m_rec.TimeZoneCode = (*m_zones)[sel-1].Index;
639 m_rec.TimeZoneValid = true;
641 else {
642 // default was selected
643 m_rec.TimeZoneValid = false;
646 // Note that recur_choice values are (zero-based) in the following
647 // order:
648 // None, Daily, Weekly, Monthly, Yearly
649 switch( m_recur_choice )
651 case RC_NONE:
652 default:
653 m_rec.Recurring = false;
654 break;
656 case RC_DAILY:
657 m_rec.Recurring = true;
658 m_rec.RecurringType = Barry::Calendar::Day;
659 break;
661 case RC_WEEKLY:
662 m_rec.Recurring = true;
663 m_rec.RecurringType = Barry::Calendar::Week;
664 m_rec.WeekDays = 0;
665 if( m_weekdays[0] ) m_rec.WeekDays |= CAL_WD_SUN;
666 if( m_weekdays[1] ) m_rec.WeekDays |= CAL_WD_MON;
667 if( m_weekdays[2] ) m_rec.WeekDays |= CAL_WD_TUE;
668 if( m_weekdays[3] ) m_rec.WeekDays |= CAL_WD_WED;
669 if( m_weekdays[4] ) m_rec.WeekDays |= CAL_WD_THU;
670 if( m_weekdays[5] ) m_rec.WeekDays |= CAL_WD_FRI;
671 if( m_weekdays[6] ) m_rec.WeekDays |= CAL_WD_SAT;
672 break;
674 case RC_MONTHLY:
675 m_rec.Recurring = true;
676 if( m_relative_date )
677 m_rec.RecurringType = Barry::Calendar::MonthByDay;
678 else
679 m_rec.RecurringType = Barry::Calendar::MonthByDate;
680 break;
682 case RC_YEARLY:
683 m_rec.Recurring = true;
684 if( m_relative_date )
685 m_rec.RecurringType = Barry::Calendar::YearByDay;
686 else
687 m_rec.RecurringType = Barry::Calendar::YearByDate;
688 break;
692 m_rec.Interval = m_interval;
694 if( !m_rec.Perpetual ) {
695 m_rec.RecurringEndTime.Time = m_RecurEndDateObj.Get();
698 return true;
701 void CalendarEditDlg::UpdateDuration()
703 TransferDataFromWindow();
705 if( m_EndDateObj.Get() < m_StartDateObj.Get() ) {
706 // error... end date cannot be before start date
707 // set end date to start date
708 m_EndDateCtrl->SetValue(m_StartDateCtrl->GetValue());
709 m_EndHoursSpinner->SetValue(m_StartHoursSpinner->GetValue());
710 m_EndMinutesSpinner->SetValue(m_StartMinutesSpinner->GetValue());
712 // duration is 0
713 m_DurationHoursSpinner->SetValue(0);
714 m_DurationMinutesSpinner->SetValue(0);
715 return;
717 else {
718 // set duration to time span of End - Start
719 time_t diff = m_EndDateObj.Get() - m_StartDateObj.Get();
720 diff /= 60; // convert to minutes
721 m_DurationHoursSpinner->SetValue(diff / 60);
722 m_DurationMinutesSpinner->SetValue(diff % 60);
726 void CalendarEditDlg::UpdateEndDate()
728 TransferDataFromWindow();
730 m_EndDateObj.Set( m_StartDateObj.Get() +
731 m_duration_hours * 60 * 60 +
732 m_duration_minutes * 60 );
734 m_EndDateCtrl->SetValue(wxDateTime(m_EndDateObj.m_date));
735 m_EndHoursSpinner->SetValue(m_EndDateObj.m_hour);
736 m_EndMinutesSpinner->SetValue(m_EndDateObj.m_min);
739 void CalendarEditDlg::EnableAllDayMode(bool all_day)
741 // if in all day mode, disable start time, end time, duration spinners
742 m_StartHoursSpinner->Enable(!all_day);
743 m_StartMinutesSpinner->Enable(!all_day);
744 m_EndHoursSpinner->Enable(!all_day);
745 m_EndMinutesSpinner->Enable(!all_day);
746 m_DurationHoursSpinner->Enable(!all_day);
747 m_DurationMinutesSpinner->Enable(!all_day);
750 void CalendarEditDlg::EnableRecurMode(bool recur)
752 RecurIntervalLabel->Show(recur);
753 RecurIntervalLabelB->Show(recur);
754 m_IntervalSpinner->Show(recur);
755 m_IntervalUnitLabel->Show(recur);
756 RecurDaysLabel->Show(recur);
757 m_SunCheck->Show(recur);
758 m_MonCheck->Show(recur);
759 m_TueCheck->Show(recur);
760 m_WedCheck->Show(recur);
761 m_ThuCheck->Show(recur);
762 m_FriCheck->Show(recur);
763 m_SatCheck->Show(recur);
764 RecurRelativeDateLabel->Show(recur);
765 m_RelativeDateCheck->Show(recur);
766 RecurEndDateLabel->Show(recur);
767 m_NeverEndsCheck->Show(recur);
768 m_RecurEndDateCtrl->Show(recur);
770 if( recur ) {
771 switch( m_RecurrenceChoice->GetSelection() )
773 case RC_NONE:
774 default:
775 m_IntervalUnitLabel->SetLabel(_T(""));
776 break;
778 case RC_DAILY:
779 m_IntervalUnitLabel->SetLabel(_T("day(s)"));
780 break;
782 case RC_WEEKLY:
783 m_IntervalUnitLabel->SetLabel(_T("week(s)"));
784 break;
786 case RC_MONTHLY:
787 m_IntervalUnitLabel->SetLabel(_T("month(s)"));
788 break;
790 case RC_YEARLY:
791 m_IntervalUnitLabel->SetLabel(_T("year(s)"));
792 break;
796 RedoLayout();