lib: added implicit ctor converter from DatabaseDatabase to DBListType
[barry/progweb.git] / desktop / src / CalendarEditDlg.cc
bloba5be5a39e8f0695c207f8bfc6011245cdfd7e675
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"
26 #include "util.h"
28 using namespace std;
29 using namespace Barry;
31 // begin wxGlade: ::extracode
32 // end wxGlade
35 //////////////////////////////////////////////////////////////////////////////
36 // CalendarEditDlg class
38 CalendarEditDlg::CalendarEditDlg(wxWindow* parent,
39 Barry::Calendar &rec,
40 bool editable,
41 const Barry::TimeZones *device_zones)
42 : wxDialog(parent, Dialog_CalendarEdit, _T("Calendar Record"))
43 , m_zones(device_zones ? device_zones : &m_static_zones)
44 , m_rec(rec)
45 , m_duration_hours(0)
46 , m_duration_minutes(0)
47 , m_reminder_hours(0)
48 , m_reminder_minutes(0)
49 , m_interval(0)
50 , m_relative_date(false)
52 // set all weekday 'bits' to false
53 for( int i = 0; i < 7; i++ )
54 m_weekdays[i] = false;
56 if( editable ) {
57 bottom_buttons = CreateButtonSizer(wxOK | wxCANCEL);
59 else {
60 bottom_buttons = CreateButtonSizer(wxCANCEL);
63 // begin wxGlade: CalendarEditDlg::CalendarEditDlg
64 label_1 = new wxStaticText(this, wxID_ANY, wxT("Subject:"));
65 m_Subject = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
66 label_2 = new wxStaticText(this, wxID_ANY, wxT("Location:"));
67 m_Location = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
68 static_line_1 = new wxStaticLine(this, wxID_ANY);
69 label_4 = new wxStaticText(this, wxID_ANY, wxT("All Day Event:"));
70 m_AllDayCheck = new wxCheckBox(this, Dialog_CalendarEdit_AllDayCheck, wxEmptyString);
71 label_5 = new wxStaticText(this, wxID_ANY, wxT("Start:"));
72 m_StartDateCtrl = new wxDatePickerCtrl(this, Dialog_CalendarEdit_StartDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
73 m_StartHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_StartHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
74 label_11 = new wxStaticText(this, wxID_ANY, wxT(":"));
75 m_StartMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_StartMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
76 label_6 = new wxStaticText(this, wxID_ANY, wxT("End:"));
77 m_EndDateCtrl = new wxDatePickerCtrl(this, Dialog_CalendarEdit_EndDateCtrl, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
78 m_EndHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_EndHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 23);
79 label_12 = new wxStaticText(this, wxID_ANY, wxT(":"));
80 m_EndMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_EndMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_WRAP|wxTE_NOHIDESEL, 0, 59);
81 label_7 = new wxStaticText(this, wxID_ANY, wxT("Duration:"));
82 m_DurationHoursSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_DurationHoursSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
83 label_13 = new wxStaticText(this, wxID_ANY, wxT("hours and"));
84 m_DurationMinutesSpinner = new wxSpinCtrl(this, Dialog_CalendarEdit_DurationMinutesSpinner, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
85 label_17 = new wxStaticText(this, wxID_ANY, wxT("minutes."));
86 label_8 = new wxStaticText(this, wxID_ANY, wxT("Time Zone:"));
87 const wxString m_TimezoneChoice_choices[] = {
88 wxT("System Time Zone")
90 m_TimezoneChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 1, m_TimezoneChoice_choices, 0);
91 label_9 = new wxStaticText(this, wxID_ANY, wxT("Show As:"));
92 const wxString m_ShowAsChoice_choices[] = {
93 wxT("Free"),
94 wxT("Tentative"),
95 wxT("Busy"),
96 wxT("Out of Office")
98 m_ShowAsChoice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 4, m_ShowAsChoice_choices, 0);
99 label_10 = new wxStaticText(this, wxID_ANY, wxT("Reminder:"));
100 m_ReminderHoursSpinner = new wxSpinCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 999);
101 label_13_copy = new wxStaticText(this, wxID_ANY, wxT("hours and"));
102 m_ReminderMinutesSpinner = new wxSpinCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 0, 59);
103 label_17_copy = new wxStaticText(this, wxID_ANY, wxT("minutes."));
104 static_line_2 = new wxStaticLine(this, wxID_ANY);
105 label_18 = new wxStaticText(this, wxID_ANY, wxT("Recurrence:"));
106 const wxString m_RecurrenceChoice_choices[] = {
107 wxT("None"),
108 wxT("Daily"),
109 wxT("Weekly"),
110 wxT("Monthly"),
111 wxT("Yearly")
113 m_RecurrenceChoice = new wxChoice(this, Dialog_CalendarEdit_RecurrenceChoice, wxDefaultPosition, wxDefaultSize, 5, m_RecurrenceChoice_choices, 0);
114 RecurIntervalLabel = new wxStaticText(this, wxID_ANY, wxT("Interval:"));
115 RecurIntervalLabelB = new wxStaticText(this, wxID_ANY, wxT("Every"));
116 m_IntervalSpinner = new wxSpinCtrl(this, wxID_ANY, wxT("1"), wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 999);
117 m_IntervalUnitLabel = new wxStaticText(this, wxID_ANY, wxT("days? weeks? months?"), wxDefaultPosition, wxDefaultSize, wxST_NO_AUTORESIZE);
118 RecurDaysLabel = new wxStaticText(this, wxID_ANY, wxT("Days:"));
119 m_SunCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
120 m_MonCheck = new wxCheckBox(this, wxID_ANY, wxT("M"));
121 m_TueCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
122 m_WedCheck = new wxCheckBox(this, wxID_ANY, wxT("W"));
123 m_ThuCheck = new wxCheckBox(this, wxID_ANY, wxT("T"));
124 m_FriCheck = new wxCheckBox(this, wxID_ANY, wxT("F"));
125 m_SatCheck = new wxCheckBox(this, wxID_ANY, wxT("S"));
126 RecurRelativeDateLabel = new wxStaticText(this, wxID_ANY, wxT("Relative Date:"));
127 m_RelativeDateCheck = new wxCheckBox(this, wxID_ANY, wxEmptyString);
128 RecurEndDateLabel = new wxStaticText(this, wxID_ANY, wxT("End Date:"));
129 m_NeverEndsCheck = new wxCheckBox(this, Dialog_CalendarEdit_NeverEndsCheck, wxT("Never ends"));
130 m_RecurEndDateCtrl = new wxDatePickerCtrl(this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY);
131 static_line_3 = new wxStaticLine(this, wxID_ANY);
132 label_14 = new wxStaticText(this, wxID_ANY, wxT("Organizer:"));
133 m_OrganizerText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
134 label_15 = new wxStaticText(this, wxID_ANY, wxT("Invited:"));
135 m_InvitedText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
136 label_16 = new wxStaticText(this, wxID_ANY, wxT("Accepted By:"));
137 m_AcceptedByText = new wxTextCtrl(this, wxID_ANY, wxEmptyString);
138 static_line_4 = new wxStaticLine(this, wxID_ANY);
139 const wxString m_ClassRadioBox_choices[] = {
140 wxT("Public"),
141 wxT("Private"),
142 wxT("Confidential")
144 m_ClassRadioBox = new wxRadioBox(this, wxID_ANY, wxT("Class"), wxDefaultPosition, wxDefaultSize, 3, m_ClassRadioBox_choices, 3, wxRA_SPECIFY_COLS);
145 static_line_5 = new wxStaticLine(this, wxID_ANY);
146 label_3 = new wxStaticText(this, wxID_ANY, wxT("Notes:"));
147 m_NotesText = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
149 set_properties();
150 do_layout();
151 // end wxGlade
153 m_top_sizer->Add(bottom_buttons, 0, wxLEFT|wxRIGHT|wxBOTTOM|wxEXPAND, 5);
155 // fill the time zone control with real time zones
156 m_TimezoneChoice->Clear();
157 m_TimezoneChoice->Append(wxT("Assume Local Timezone"), (void*)0);
158 Barry::TimeZones::const_iterator b, e;
159 for( b = m_zones->begin(), e = m_zones->end(); b != e; ++b ) {
160 m_TimezoneChoice->Append(
161 wxString(b->GetDescription().c_str(), wxConvUTF8),
162 (void*) &b->Index);
164 m_TimezoneChoice->SetSelection(0);
166 // layout again, in case sizes are different
167 RedoLayout();
170 void CalendarEditDlg::RedoLayout()
172 m_top_sizer->Fit(this);
173 Layout();
176 BEGIN_EVENT_TABLE(CalendarEditDlg, wxDialog)
177 // begin wxGlade: CalendarEditDlg::event_table
178 EVT_CHECKBOX(Dialog_CalendarEdit_AllDayCheck, CalendarEditDlg::OnAllDayEvent)
179 EVT_DATE_CHANGED(Dialog_CalendarEdit_StartDateCtrl, CalendarEditDlg::OnStartDateChanged)
180 EVT_SPINCTRL(Dialog_CalendarEdit_StartHoursSpinner, CalendarEditDlg::OnStartHoursSpin)
181 EVT_SPINCTRL(Dialog_CalendarEdit_StartMinutesSpinner, CalendarEditDlg::OnStartMinutesSpin)
182 EVT_DATE_CHANGED(Dialog_CalendarEdit_EndDateCtrl, CalendarEditDlg::OnEndDateChanged)
183 EVT_SPINCTRL(Dialog_CalendarEdit_EndHoursSpinner, CalendarEditDlg::OnEndHoursSpin)
184 EVT_SPINCTRL(Dialog_CalendarEdit_EndMinutesSpinner, CalendarEditDlg::OnEndMinutesSpin)
185 EVT_SPINCTRL(Dialog_CalendarEdit_DurationHoursSpinner, CalendarEditDlg::OnDurationHoursSpin)
186 EVT_SPINCTRL(Dialog_CalendarEdit_DurationMinutesSpinner, CalendarEditDlg::OnDurationMinutesSpin)
187 EVT_CHOICE(Dialog_CalendarEdit_RecurrenceChoice, CalendarEditDlg::OnRecurrenceChoice)
188 EVT_CHECKBOX(Dialog_CalendarEdit_NeverEndsCheck, CalendarEditDlg::OnEndDateCheckbox)
189 // end wxGlade
190 END_EVENT_TABLE();
193 void CalendarEditDlg::OnAllDayEvent(wxCommandEvent &event)
195 bool checked = m_AllDayCheck->IsChecked();
197 if( checked ) {
198 // set start time to date at 00:00 and end time at
199 // day + 1 at 00:00
201 // time
202 m_StartHoursSpinner->SetValue(0);
203 m_StartMinutesSpinner->SetValue(0);
204 m_EndHoursSpinner->SetValue(0);
205 m_EndMinutesSpinner->SetValue(0);
207 // date
208 m_StartDateCtrl->SetValue(m_StartDateCtrl->GetValue().GetDateOnly());
209 m_EndDateCtrl->SetValue(m_StartDateCtrl->GetValue().GetDateOnly() + wxDateSpan::Day());
211 // duration
212 m_DurationHoursSpinner->SetValue(24);
213 m_DurationMinutesSpinner->SetValue(0);
216 EnableAllDayMode(checked);
219 void CalendarEditDlg::OnStartDateChanged(wxDateEvent &event)
221 UpdateDuration();
224 void CalendarEditDlg::OnStartHoursSpin(wxSpinEvent &event)
226 UpdateDuration();
229 void CalendarEditDlg::OnStartMinutesSpin(wxSpinEvent &event)
231 UpdateDuration();
234 void CalendarEditDlg::OnEndDateChanged(wxDateEvent &event)
236 UpdateDuration();
239 void CalendarEditDlg::OnEndHoursSpin(wxSpinEvent &event)
241 UpdateDuration();
244 void CalendarEditDlg::OnEndMinutesSpin(wxSpinEvent &event)
246 UpdateDuration();
249 void CalendarEditDlg::OnDurationHoursSpin(wxSpinEvent &event)
251 UpdateEndDate();
254 void CalendarEditDlg::OnDurationMinutesSpin(wxSpinEvent &event)
256 UpdateEndDate();
259 void CalendarEditDlg::OnRecurrenceChoice(wxCommandEvent &event)
261 TransferDataFromWindow();
262 EnableRecurMode(m_rec.Recurring);
266 void CalendarEditDlg::OnEndDateCheckbox(wxCommandEvent &event)
268 m_RecurEndDateCtrl->Enable( !m_NeverEndsCheck->IsChecked() );
272 // wxGlade: add CalendarEditDlg event handlers
275 void CalendarEditDlg::set_properties()
277 // begin wxGlade: CalendarEditDlg::set_properties
278 SetTitle(wxT("Calendar Event"));
279 m_Subject->SetFocus();
280 m_Subject->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Subject)));
281 m_Location->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Location)));
282 m_AllDayCheck->SetValidator(wxGenericValidator(&m_rec.AllDayEvent));
283 m_StartDateCtrl->SetMinSize(wxSize(110, -1));
284 m_StartDateCtrl->SetValidator(DateTimeValidator(&m_StartDateObj.m_date));
285 m_StartHoursSpinner->SetMinSize(wxSize(45, -1));
286 m_StartHoursSpinner->SetValidator(wxGenericValidator(&m_StartDateObj.m_hour));
287 m_StartMinutesSpinner->SetMinSize(wxSize(45, -1));
288 m_StartMinutesSpinner->SetValidator(wxGenericValidator(&m_StartDateObj.m_min));
289 m_EndDateCtrl->SetMinSize(wxSize(110, -1));
290 m_EndDateCtrl->SetValidator(DateTimeValidator(&m_EndDateObj.m_date));
291 m_EndHoursSpinner->SetMinSize(wxSize(45, -1));
292 m_EndHoursSpinner->SetValidator(wxGenericValidator(&m_EndDateObj.m_hour));
293 m_EndMinutesSpinner->SetMinSize(wxSize(45, -1));
294 m_EndMinutesSpinner->SetValidator(wxGenericValidator(&m_EndDateObj.m_min));
295 m_DurationHoursSpinner->SetMinSize(wxSize(45, -1));
296 m_DurationHoursSpinner->SetValidator(wxGenericValidator(&m_duration_hours));
297 m_DurationMinutesSpinner->SetMinSize(wxSize(45, -1));
298 m_DurationMinutesSpinner->SetValidator(wxGenericValidator(&m_duration_minutes));
299 m_TimezoneChoice->SetSelection(0);
300 m_ShowAsChoice->SetSelection(2);
301 m_ReminderHoursSpinner->SetMinSize(wxSize(45, -1));
302 m_ReminderHoursSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
303 m_ReminderHoursSpinner->SetValidator(wxGenericValidator(&m_reminder_hours));
304 m_ReminderMinutesSpinner->SetMinSize(wxSize(45, -1));
305 m_ReminderMinutesSpinner->SetToolTip(wxT("Set Reminder to 0 to disable"));
306 m_ReminderMinutesSpinner->SetValidator(wxGenericValidator(&m_reminder_minutes));
307 m_RecurrenceChoice->SetValidator(wxGenericValidator(&m_recur_choice));
308 m_RecurrenceChoice->SetSelection(0);
309 m_IntervalSpinner->SetMinSize(wxSize(45, -1));
310 m_IntervalSpinner->SetValidator(wxGenericValidator(&m_interval));
311 m_SunCheck->SetValidator(wxGenericValidator(&m_weekdays[0]));
312 m_MonCheck->SetValidator(wxGenericValidator(&m_weekdays[1]));
313 m_TueCheck->SetValidator(wxGenericValidator(&m_weekdays[2]));
314 m_WedCheck->SetValidator(wxGenericValidator(&m_weekdays[3]));
315 m_ThuCheck->SetValidator(wxGenericValidator(&m_weekdays[4]));
316 m_FriCheck->SetValidator(wxGenericValidator(&m_weekdays[5]));
317 m_SatCheck->SetValidator(wxGenericValidator(&m_weekdays[6]));
318 RecurRelativeDateLabel->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->SetToolTip(wxT("Relative monthly or yearly dates take the weekday of the start date into account. (eg. every first Sunday of month)"));
320 m_RelativeDateCheck->SetValidator(wxGenericValidator(&m_relative_date));
321 m_NeverEndsCheck->SetValidator(wxGenericValidator(&m_rec.Perpetual));
322 m_NeverEndsCheck->SetValue(1);
323 m_RecurEndDateCtrl->SetMinSize(wxSize(110, -1));
324 m_RecurEndDateCtrl->Enable(false);
325 m_RecurEndDateCtrl->SetValidator(DateTimeValidator(&m_RecurEndDateObj.m_date));
326 m_OrganizerText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_organizer)));
327 m_InvitedText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_invited)));
328 m_AcceptedByText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_accepted_by)));
329 m_ClassRadioBox->SetValidator(MakeRadioBoxValidator(&m_rec.ClassFlag).Add(Barry::Calendar::Public).Add(Barry::Calendar::Private).Add(Barry::Calendar::Confidential));
330 m_ClassRadioBox->SetSelection(0);
331 m_NotesText->SetMinSize(wxSize(-1, 61));
332 m_NotesText->SetValidator(wxTextValidator(wxFILTER_NONE, m_strings.Add(m_rec.Notes)));
333 // end wxGlade
337 void CalendarEditDlg::do_layout()
339 // begin wxGlade: CalendarEditDlg::do_layout
340 wxBoxSizer* sizer_surround = new wxBoxSizer(wxVERTICAL);
341 wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
342 wxBoxSizer* sizer_2 = new wxBoxSizer(wxHORIZONTAL);
343 wxFlexGridSizer* grid_sizer_3 = new wxFlexGridSizer(3, 2, 5, 5);
344 wxFlexGridSizer* grid_sizer_4 = new wxFlexGridSizer(5, 2, 5, 5);
345 wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
346 wxBoxSizer* m_DaysCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
347 wxBoxSizer* m_IntervalCtrlsSizer = new wxBoxSizer(wxHORIZONTAL);
348 wxFlexGridSizer* grid_sizer_2 = new wxFlexGridSizer(7, 2, 5, 5);
349 wxBoxSizer* sizer_5_copy = new wxBoxSizer(wxHORIZONTAL);
350 wxBoxSizer* sizer_5 = new wxBoxSizer(wxHORIZONTAL);
351 wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
352 wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
353 wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer(2, 2, 5, 5);
354 grid_sizer_1->Add(label_1, 0, 0, 0);
355 grid_sizer_1->Add(m_Subject, 0, wxEXPAND, 0);
356 grid_sizer_1->Add(label_2, 0, 0, 0);
357 grid_sizer_1->Add(m_Location, 0, wxEXPAND, 0);
358 grid_sizer_1->AddGrowableCol(1);
359 sizer_1->Add(grid_sizer_1, 0, wxEXPAND, 0);
360 sizer_1->Add(static_line_1, 0, wxALL|wxEXPAND, 5);
361 grid_sizer_2->Add(label_4, 0, 0, 0);
362 grid_sizer_2->Add(m_AllDayCheck, 0, 0, 0);
363 grid_sizer_2->Add(label_5, 0, wxALIGN_CENTER_VERTICAL, 0);
364 sizer_3->Add(m_StartDateCtrl, 0, 0, 0);
365 sizer_3->Add(20, 20, 0, 0, 0);
366 sizer_3->Add(m_StartHoursSpinner, 0, 0, 0);
367 sizer_3->Add(label_11, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 1);
368 sizer_3->Add(m_StartMinutesSpinner, 0, 0, 0);
369 grid_sizer_2->Add(sizer_3, 1, wxEXPAND, 0);
370 grid_sizer_2->Add(label_6, 0, wxALIGN_CENTER_VERTICAL, 0);
371 sizer_4->Add(m_EndDateCtrl, 0, 0, 0);
372 sizer_4->Add(20, 20, 0, 0, 0);
373 sizer_4->Add(m_EndHoursSpinner, 0, 0, 0);
374 sizer_4->Add(label_12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 1);
375 sizer_4->Add(m_EndMinutesSpinner, 0, 0, 0);
376 grid_sizer_2->Add(sizer_4, 1, wxEXPAND, 0);
377 grid_sizer_2->Add(label_7, 0, wxALIGN_CENTER_VERTICAL, 0);
378 sizer_5->Add(m_DurationHoursSpinner, 0, wxRIGHT, 5);
379 sizer_5->Add(label_13, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
380 sizer_5->Add(m_DurationMinutesSpinner, 0, wxRIGHT, 5);
381 sizer_5->Add(label_17, 0, wxALIGN_CENTER_VERTICAL, 0);
382 grid_sizer_2->Add(sizer_5, 1, wxEXPAND, 0);
383 grid_sizer_2->Add(label_8, 0, wxALIGN_CENTER_VERTICAL, 0);
384 grid_sizer_2->Add(m_TimezoneChoice, 0, 0, 0);
385 grid_sizer_2->Add(label_9, 0, wxALIGN_CENTER_VERTICAL, 0);
386 grid_sizer_2->Add(m_ShowAsChoice, 0, 0, 0);
387 grid_sizer_2->Add(label_10, 0, wxALIGN_CENTER_VERTICAL, 0);
388 sizer_5_copy->Add(m_ReminderHoursSpinner, 0, wxRIGHT, 5);
389 sizer_5_copy->Add(label_13_copy, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
390 sizer_5_copy->Add(m_ReminderMinutesSpinner, 0, wxRIGHT, 5);
391 sizer_5_copy->Add(label_17_copy, 0, wxALIGN_CENTER_VERTICAL, 0);
392 grid_sizer_2->Add(sizer_5_copy, 1, wxEXPAND, 0);
393 grid_sizer_2->AddGrowableCol(1);
394 sizer_1->Add(grid_sizer_2, 0, wxEXPAND, 0);
395 sizer_1->Add(static_line_2, 0, wxALL|wxEXPAND, 5);
396 grid_sizer_4->Add(label_18, 0, wxALIGN_CENTER_VERTICAL, 0);
397 grid_sizer_4->Add(m_RecurrenceChoice, 0, 0, 0);
398 grid_sizer_4->Add(RecurIntervalLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
399 m_IntervalCtrlsSizer->Add(RecurIntervalLabelB, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
400 m_IntervalCtrlsSizer->Add(m_IntervalSpinner, 0, wxRIGHT, 5);
401 m_IntervalCtrlsSizer->Add(m_IntervalUnitLabel, 1, wxALIGN_CENTER_VERTICAL, 0);
402 grid_sizer_4->Add(m_IntervalCtrlsSizer, 1, wxEXPAND, 0);
403 grid_sizer_4->Add(RecurDaysLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
404 m_DaysCtrlsSizer->Add(m_SunCheck, 0, wxRIGHT, 5);
405 m_DaysCtrlsSizer->Add(m_MonCheck, 0, wxRIGHT, 5);
406 m_DaysCtrlsSizer->Add(m_TueCheck, 0, wxRIGHT, 5);
407 m_DaysCtrlsSizer->Add(m_WedCheck, 0, wxRIGHT, 5);
408 m_DaysCtrlsSizer->Add(m_ThuCheck, 0, wxRIGHT, 5);
409 m_DaysCtrlsSizer->Add(m_FriCheck, 0, wxRIGHT, 5);
410 m_DaysCtrlsSizer->Add(m_SatCheck, 0, wxRIGHT, 5);
411 grid_sizer_4->Add(m_DaysCtrlsSizer, 1, wxEXPAND, 0);
412 grid_sizer_4->Add(RecurRelativeDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
413 grid_sizer_4->Add(m_RelativeDateCheck, 0, 0, 0);
414 grid_sizer_4->Add(RecurEndDateLabel, 0, wxALIGN_CENTER_VERTICAL, 0);
415 sizer_8->Add(m_NeverEndsCheck, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 10);
416 sizer_8->Add(m_RecurEndDateCtrl, 0, wxALIGN_CENTER_VERTICAL, 0);
417 grid_sizer_4->Add(sizer_8, 1, wxEXPAND, 0);
418 grid_sizer_4->AddGrowableCol(1);
419 sizer_1->Add(grid_sizer_4, 0, wxEXPAND, 0);
420 sizer_1->Add(static_line_3, 0, wxALL|wxEXPAND, 5);
421 grid_sizer_3->Add(label_14, 0, wxALIGN_CENTER_VERTICAL, 0);
422 grid_sizer_3->Add(m_OrganizerText, 0, wxEXPAND, 0);
423 grid_sizer_3->Add(label_15, 0, wxALIGN_CENTER_VERTICAL, 0);
424 grid_sizer_3->Add(m_InvitedText, 0, wxEXPAND, 0);
425 grid_sizer_3->Add(label_16, 0, wxALIGN_CENTER_VERTICAL, 0);
426 grid_sizer_3->Add(m_AcceptedByText, 0, wxEXPAND, 0);
427 grid_sizer_3->AddGrowableCol(1);
428 sizer_1->Add(grid_sizer_3, 0, wxEXPAND, 0);
429 sizer_1->Add(static_line_4, 0, wxALL|wxEXPAND, 5);
430 sizer_1->Add(m_ClassRadioBox, 0, wxEXPAND, 0);
431 sizer_1->Add(static_line_5, 0, wxALL|wxEXPAND, 5);
432 sizer_2->Add(label_3, 0, wxRIGHT, 5);
433 sizer_2->Add(m_NotesText, 1, wxEXPAND, 0);
434 sizer_1->Add(sizer_2, 1, wxEXPAND, 0);
435 sizer_surround->Add(sizer_1, 1, wxALL|wxEXPAND, 10);
436 SetSizer(sizer_surround);
437 sizer_surround->Fit(this);
438 Layout();
439 // end wxGlade
441 m_top_sizer = sizer_surround;
444 bool CalendarEditDlg::TransferDataToWindow()
446 // prepare temporary variables, from record
448 m_organizer = m_rec.Organizer.ToCommaSeparated();
449 m_invited = m_rec.Invited.ToCommaSeparated();
450 m_accepted_by = m_rec.AcceptedBy.ToCommaSeparated();
452 m_StartDateObj.Set(m_rec.StartTime.Time);
453 m_EndDateObj.Set(m_rec.EndTime.Time);
455 int duration = m_rec.EndTime.Time - m_rec.StartTime.Time;
456 duration /= 60; // convert to minutes
457 if( m_rec.EndTime.Time >= m_rec.StartTime.Time ) {
458 m_duration_hours = duration / 60;
459 m_duration_minutes = duration % 60;
462 if( m_rec.NotificationTime.Time ) {
463 int span = m_rec.StartTime.Time - m_rec.NotificationTime.Time;
464 span /= 60; // convert to minutes
465 if( m_rec.StartTime.Time > m_rec.NotificationTime.Time ) {
466 m_reminder_hours = span / 60;
467 m_reminder_minutes = span % 60;
469 else {
470 m_reminder_hours = 0;
471 m_reminder_minutes = 15;
475 EnableAllDayMode(m_rec.AllDayEvent);
477 // set the timezone choice only if the record's data is valid
478 m_TimezoneChoice->SetSelection(0); // default to none
479 if( m_rec.TimeZoneValid ) {
480 TimeZones::const_iterator i = m_zones->Find(m_rec.TimeZoneCode);
481 if( i != m_zones->end() ) {
482 int array_index = i - m_zones->begin();
483 // select item, skipping 0's "none" option
484 m_TimezoneChoice->SetSelection(array_index + 1);
488 #define SA_FREE 0
489 #define SA_TENTATIVE 1
490 #define SA_BUSY 2
491 #define SA_OUT_OF_OFFICE 3
492 switch( m_rec.FreeBusyFlag )
494 case Barry::Calendar::Free:
495 m_ShowAsChoice->SetSelection(SA_FREE);
496 break;
498 case Barry::Calendar::Tentative:
499 m_ShowAsChoice->SetSelection(SA_TENTATIVE);
500 break;
502 case Barry::Calendar::Busy:
503 default:
504 m_ShowAsChoice->SetSelection(SA_BUSY);
505 break;
507 case Barry::Calendar::OutOfOffice:
508 m_ShowAsChoice->SetSelection(SA_OUT_OF_OFFICE);
509 break;
512 // Note that recur_choice values are (zero-based) in the following
513 // order:
514 // None, Daily, Weekly, Monthly, Yearly
515 #define RC_NONE 0
516 #define RC_DAILY 1
517 #define RC_WEEKLY 2
518 #define RC_MONTHLY 3
519 #define RC_YEARLY 4
521 if( m_rec.Recurring ) {
522 switch( m_rec.RecurringType )
524 case Barry::RecurBase::Day:
525 m_recur_choice = RC_DAILY;
526 m_relative_date = false;
527 break;
529 case Barry::RecurBase::MonthByDate:
530 m_recur_choice = RC_MONTHLY;
531 m_relative_date = false;
532 break;
534 case Barry::RecurBase::MonthByDay:
535 m_recur_choice = RC_MONTHLY;
536 m_relative_date = true;
537 break;
539 case Barry::RecurBase::YearByDate:
540 m_recur_choice = RC_YEARLY;
541 m_relative_date = false;
542 break;
544 case Barry::RecurBase::YearByDay:
545 m_recur_choice = RC_YEARLY;
546 m_relative_date = true;
547 break;
549 case Barry::RecurBase::Week:
550 m_recur_choice = RC_WEEKLY;
551 m_relative_date = false;
552 m_weekdays[0] = m_rec.WeekDays & CAL_WD_SUN;
553 m_weekdays[1] = m_rec.WeekDays & CAL_WD_MON;
554 m_weekdays[2] = m_rec.WeekDays & CAL_WD_TUE;
555 m_weekdays[3] = m_rec.WeekDays & CAL_WD_WED;
556 m_weekdays[4] = m_rec.WeekDays & CAL_WD_THU;
557 m_weekdays[5] = m_rec.WeekDays & CAL_WD_FRI;
558 m_weekdays[6] = m_rec.WeekDays & CAL_WD_SAT;
559 break;
561 default:
562 cerr << "Bad RecurringType in CalendarEditDlg" << endl;
563 m_recur_choice = RC_NONE;
564 m_relative_date = false;
567 else {
568 m_recur_choice = RC_NONE;
569 m_relative_date = false;
572 m_interval = m_rec.Interval;
574 m_RecurEndDateObj.Set(m_rec.RecurringEndTime.Time);
575 if( m_rec.Perpetual ) {
576 m_RecurEndDateCtrl->Enable(false);
578 else {
579 m_RecurEndDateCtrl->Enable();
582 EnableRecurMode(m_rec.Recurring);
584 m_strings.RefreshWx();
586 // let the base class call the validaors to do the rest
587 if( wxDialog::TransferDataToWindow() ) {
588 // on success, do just a little bit of fine tuning
589 MakeDateRecent(true, m_StartDateCtrl);
590 MakeDateRecent(true, m_EndDateCtrl);
591 MakeDateRecent(true, m_RecurEndDateCtrl);
592 return true;
594 else {
595 return false;
599 bool CalendarEditDlg::TransferDataFromWindow()
601 if( !wxDialog::TransferDataFromWindow() )
602 return false;
604 m_strings.Sync();
606 m_rec.Organizer.clear();
607 m_rec.Organizer.AddCommaSeparated(m_organizer);
609 m_rec.Invited.clear();
610 m_rec.Invited.AddCommaSeparated(m_invited);
612 m_rec.AcceptedBy.clear();
613 m_rec.AcceptedBy.AddCommaSeparated(m_accepted_by);
615 m_rec.StartTime.Time = m_StartDateObj.Get();
616 m_rec.EndTime.Time = m_EndDateObj.Get();
617 if( m_rec.EndTime.Time < m_rec.StartTime.Time ) {
618 wxMessageBox(_T("Start time must come before end time."),
619 _T("Validation Error"), wxOK | wxICON_INFORMATION);
620 return false;
623 int span = ((m_reminder_hours * 60) + m_reminder_minutes) * 60;
624 m_rec.NotificationTime.Time = m_rec.StartTime.Time - span;
626 switch( m_ShowAsChoice->GetSelection() )
628 case SA_FREE:
629 m_rec.FreeBusyFlag = Barry::Calendar::Free;
630 break;
632 case SA_TENTATIVE:
633 m_rec.FreeBusyFlag = Barry::Calendar::Tentative;
634 break;
636 case SA_BUSY:
637 default:
638 m_rec.FreeBusyFlag = Barry::Calendar::Busy;
639 break;
641 case SA_OUT_OF_OFFICE:
642 m_rec.FreeBusyFlag = Barry::Calendar::OutOfOffice;
643 break;
646 // set the timezone choice only if the record's data is valid
647 int sel = m_TimezoneChoice->GetSelection();
648 if( sel > 0 ) {
649 m_rec.TimeZoneCode = (*m_zones)[sel-1].Index;
650 m_rec.TimeZoneValid = true;
652 else {
653 // default was selected
654 m_rec.TimeZoneValid = false;
657 // Note that recur_choice values are (zero-based) in the following
658 // order:
659 // None, Daily, Weekly, Monthly, Yearly
660 switch( m_recur_choice )
662 case RC_NONE:
663 default:
664 m_rec.Recurring = false;
665 break;
667 case RC_DAILY:
668 m_rec.Recurring = true;
669 m_rec.RecurringType = Barry::RecurBase::Day;
670 break;
672 case RC_WEEKLY:
673 m_rec.Recurring = true;
674 m_rec.RecurringType = Barry::RecurBase::Week;
675 m_rec.WeekDays = 0;
676 if( m_weekdays[0] ) m_rec.WeekDays |= CAL_WD_SUN;
677 if( m_weekdays[1] ) m_rec.WeekDays |= CAL_WD_MON;
678 if( m_weekdays[2] ) m_rec.WeekDays |= CAL_WD_TUE;
679 if( m_weekdays[3] ) m_rec.WeekDays |= CAL_WD_WED;
680 if( m_weekdays[4] ) m_rec.WeekDays |= CAL_WD_THU;
681 if( m_weekdays[5] ) m_rec.WeekDays |= CAL_WD_FRI;
682 if( m_weekdays[6] ) m_rec.WeekDays |= CAL_WD_SAT;
683 break;
685 case RC_MONTHLY:
686 m_rec.Recurring = true;
687 if( m_relative_date )
688 m_rec.RecurringType = Barry::RecurBase::MonthByDay;
689 else
690 m_rec.RecurringType = Barry::RecurBase::MonthByDate;
691 break;
693 case RC_YEARLY:
694 m_rec.Recurring = true;
695 if( m_relative_date )
696 m_rec.RecurringType = Barry::RecurBase::YearByDay;
697 else
698 m_rec.RecurringType = Barry::RecurBase::YearByDate;
699 break;
703 m_rec.Interval = m_interval;
705 if( !m_rec.Perpetual ) {
706 m_rec.RecurringEndTime.Time = m_RecurEndDateObj.Get();
709 return true;
712 void CalendarEditDlg::UpdateDuration()
714 TransferDataFromWindow();
716 if( m_EndDateObj.Get() < m_StartDateObj.Get() ) {
717 // error... end date cannot be before start date
718 // set end date to start date
719 m_EndDateCtrl->SetValue(m_StartDateCtrl->GetValue());
720 m_EndHoursSpinner->SetValue(m_StartHoursSpinner->GetValue());
721 m_EndMinutesSpinner->SetValue(m_StartMinutesSpinner->GetValue());
723 // duration is 0
724 m_DurationHoursSpinner->SetValue(0);
725 m_DurationMinutesSpinner->SetValue(0);
726 return;
728 else {
729 // set duration to time span of End - Start
730 time_t diff = m_EndDateObj.Get() - m_StartDateObj.Get();
731 diff /= 60; // convert to minutes
732 m_DurationHoursSpinner->SetValue(diff / 60);
733 m_DurationMinutesSpinner->SetValue(diff % 60);
737 void CalendarEditDlg::UpdateEndDate()
739 TransferDataFromWindow();
741 m_EndDateObj.Set( m_StartDateObj.Get() +
742 m_duration_hours * 60 * 60 +
743 m_duration_minutes * 60 );
745 m_EndDateCtrl->SetValue(wxDateTime(m_EndDateObj.m_date));
746 m_EndHoursSpinner->SetValue(m_EndDateObj.m_hour);
747 m_EndMinutesSpinner->SetValue(m_EndDateObj.m_min);
750 void CalendarEditDlg::EnableAllDayMode(bool all_day)
752 // if in all day mode, disable start time, end time, duration spinners
753 m_StartHoursSpinner->Enable(!all_day);
754 m_StartMinutesSpinner->Enable(!all_day);
755 m_EndHoursSpinner->Enable(!all_day);
756 m_EndMinutesSpinner->Enable(!all_day);
757 m_DurationHoursSpinner->Enable(!all_day);
758 m_DurationMinutesSpinner->Enable(!all_day);
761 void CalendarEditDlg::EnableRecurMode(bool recur)
763 // show all controls
764 RecurIntervalLabel->Show(recur);
765 RecurIntervalLabelB->Show(recur);
766 m_IntervalSpinner->Show(recur);
767 m_IntervalUnitLabel->Show(recur);
768 RecurDaysLabel->Show(recur);
769 m_SunCheck->Show(recur);
770 m_MonCheck->Show(recur);
771 m_TueCheck->Show(recur);
772 m_WedCheck->Show(recur);
773 m_ThuCheck->Show(recur);
774 m_FriCheck->Show(recur);
775 m_SatCheck->Show(recur);
776 RecurRelativeDateLabel->Show(recur);
777 m_RelativeDateCheck->Show(recur);
778 RecurEndDateLabel->Show(recur);
779 m_NeverEndsCheck->Show(recur);
780 m_RecurEndDateCtrl->Show(recur);
782 // enable based on choice
783 int choice = m_RecurrenceChoice->GetSelection();
784 m_SunCheck->Enable(choice == RC_WEEKLY);
785 m_MonCheck->Enable(choice == RC_WEEKLY);
786 m_TueCheck->Enable(choice == RC_WEEKLY);
787 m_WedCheck->Enable(choice == RC_WEEKLY);
788 m_ThuCheck->Enable(choice == RC_WEEKLY);
789 m_FriCheck->Enable(choice == RC_WEEKLY);
790 m_SatCheck->Enable(choice == RC_WEEKLY);
792 // update labels
793 if( recur ) {
794 switch( m_RecurrenceChoice->GetSelection() )
796 case RC_NONE:
797 default:
798 m_IntervalUnitLabel->SetLabel(_T(""));
799 break;
801 case RC_DAILY:
802 m_IntervalUnitLabel->SetLabel(_T("day(s)"));
803 break;
805 case RC_WEEKLY:
806 m_IntervalUnitLabel->SetLabel(_T("week(s)"));
807 break;
809 case RC_MONTHLY:
810 m_IntervalUnitLabel->SetLabel(_T("month(s)"));
811 break;
813 case RC_YEARLY:
814 m_IntervalUnitLabel->SetLabel(_T("year(s)"));
815 break;
819 RedoLayout();
824 // Note: this file is very similar to TaskEditDlg.cc, and should be kept
825 // in lock step as much as possible. They are in separate files, since
826 // the GUI code is generated with wxglade