1 // XCCalendarDay.cpp - Xestia Calendar XCCalendarDay widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "XCCalendarDay.h"
23 BEGIN_EVENT_TABLE(XCCalendarDay, wxPanel)
24 EVT_PAINT(XCCalendarDay::PaintFrameEvent)
25 EVT_SIZE(XCCalendarDay::ResizeFrameEvent)
28 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
29 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
31 this->SetMinSize( wxSize( 100,100 ) );
35 wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
36 wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
38 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
39 wxBitmap imgAlertIcon(icons_alert_png, -1);
41 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
42 wxBitmap imgPriorityIcon(icons_priority_png, -1);
44 AlertIcon->SetBitmap(imgAlertIcon);
45 HighPriorityIcon->SetBitmap(imgPriorityIcon);
47 WindowSizer->AddGrowableCol(0);
48 WindowSizer->AddGrowableRow(1);
49 WindowSizer->SetFlexibleDirection( wxBOTH );
50 WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
52 NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
53 NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
55 TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
56 TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
57 TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
58 TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
60 // Setup the scrollable section.
63 EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
65 EventListFrame->SetSizer(EventListFrameSizer);
67 EventListFrame->SetScrollRate(0,1);
68 //EventListFrameSizer->FitInside(EventListFrame);
69 EventListFrameSizer->Fit(EventListFrame);
70 EventListFrameSizer->Layout();
71 WindowSizer->Fit(this);
73 // Setup the scroll window.
75 MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
77 WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
78 WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
80 this->SetSizer(WindowSizer);
83 this->SetBackgroundStyle(wxBG_STYLE_PAINT);
88 Connect(ID_DESELECTOTHERENTRIES, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
89 Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
90 Connect(ID_HIDEENTRIES, XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::HideAccountEntries));
91 Connect(ID_SHOWENTRIES, XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::ShowAccountEntries));
92 Connect(ID_HIDECALENDARENTRIES, XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::HideCalendarEntries));
93 Connect(ID_SHOWCALENDARENTRIES, XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::ShowCalendarEntries));
94 Connect(ID_DELETECALENDARENTRIES, XCCALENDARDAY_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::DeleteCalendarEntries));
95 Connect(ID_DELETEENTRY, XCCALENDARDAY_DELETEENTRY, wxCommandEventHandler(XCCalendarDay::DeleteCalendarEntry));
96 Connect(ID_ADDENTRY, XCCALENDARDAY_ADDENTRY, wxCommandEventHandler(XCCalendarDay::AddCalendarEntry));
97 Connect(ID_UPDATEENTRY, XCCALENDARDAY_UPDATEENTRY, wxCommandEventHandler(XCCalendarDay::UpdateCalendarEntry));
98 Connect(ID_UPDATECOLOUR, XCCALENDARDAY_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarDay::UpdateCalendarColour));
102 XCCalendarDay::~XCCalendarDay(){
104 // Destory the controls from the widget.
106 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
107 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
109 delete((*CalendarEntryIter));
113 CalendarEntryList.clear();
119 void XCCalendarDay::Repaint(){
122 wxPaintDC EventListFrameDC(EventListFrame);
124 // Get the wxSizerItem for the top date and the entries part.
126 wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
127 wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
128 wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
130 if (IsInMonth == true){
132 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
133 dc.SetBrush(wxBrush(wxColor(255,255,255)));
134 dc.DrawRectangle(TopSectionSizerItem->GetRect());
135 dc.SetBrush(wxBrush(wxColor(225,225,225)));
136 dc.DrawRectangle(MainSectionSizerItem->GetRect());
137 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
138 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
139 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
143 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
144 dc.SetBrush(wxBrush(wxColor(185,185,185)));
145 dc.DrawRectangle(TopSectionSizerItem->GetRect());
146 dc.SetBrush(wxBrush(wxColor(155,155,155)));
147 dc.DrawRectangle(MainSectionSizerItem->GetRect());
148 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
149 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
150 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
156 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
162 void XCCalendarDay::UpdateTopIcons(){
164 bool AlarmFound = false;
165 bool HighPriorityFound = false;
167 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
168 EntryIter != CalendarEntryList.end(); EntryIter++){
170 if ((*EntryIter)->GetDisplayAlarm() == true){
176 if ((*EntryIter)->GetDisplayHighPriority() == true){
178 HighPriorityFound = true;
182 if (AlarmFound == true && HighPriorityFound == true){
190 AlertIcon->Show(AlarmFound);
191 HighPriorityIcon->Show(HighPriorityFound);
195 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
202 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
205 // TODO: Check if window size is less than 120 pixels and if it is,
206 // switch to the small block mode.
208 // Refresh the window.
214 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
217 int SelectedEntryID = DeselectEvent.GetInt();
219 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
220 DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
222 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
223 EntryIter != CalendarEntryList.end(); EntryIter++){
225 if ((*EntryIter)->GetID() != SelectedEntryID){
227 wxPostEvent((*EntryIter), DeselectEntryEvent);
233 // Send event notification to deselect the other calendar entries.
235 if (this->MonthViewPointer != nullptr){
237 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
238 DeselectEvent.SetClientData(this);
239 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
240 wxPostEvent(this->MonthViewPointer, DeselectEvent);
246 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
249 int SelectedEntryID = DeselectEvent.GetInt();
251 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
252 DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
254 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
255 EntryIter != CalendarEntryList.end(); EntryIter++){
257 wxPostEvent((*EntryIter), DeselectEntryEvent);
263 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
266 this->dataStorage = dataStorage;
270 NumberText->SetLabel(wxString::Format("%02i", SetupDay));
271 calendarDay = SetupDay;
275 calendarMonth = SetupMonth;
279 calendarYear = SetupYear;
281 // Setup the Is In Month value.
283 IsInMonth = SetupIsInMonth;
285 // Setup the month view pointer.
287 this->MonthViewPointer = MonthViewPointer;
289 // Setup the calendar items.
291 CDSEntryList calendarItems = dataStorage->GetEventListByDate(SetupYear, SetupMonth, SetupDay);
293 for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
295 // Get the information about the calendar entry.
297 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
298 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
300 // Setup the calendar entry.
302 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
304 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
305 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
306 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
308 EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
309 wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
311 newEntry->SetAfterSpacer(afterSpacer);
313 // Go through the list of calendar entries to hide by account.
315 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
316 hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
318 if (*hideAccountsItem == newEntryCalendarInfo.accountID){
319 newEntry->Show(false);
320 newEntry->GetAfterSpacer()->Show(false);
325 // Go through the list of calendar entries to hide by calendar.
327 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
328 hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
330 if (*hideCalendarsItem == newEntryInfo.calendarID){
331 newEntry->Show(false);
332 newEntry->GetAfterSpacer()->Show(false);
337 CalendarEntryList.push_back(newEntry);
342 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
344 // Go through each of the controls and hide the controls (and spacing) that
345 // have the matched account IDs.
347 int sizerPosition = 0;
349 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
350 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
352 (*CalendarEntryIter)->SetShowAccountStatus(false);
354 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
356 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
357 (*CalendarEntryIter)->Show(false);
359 // Get the spacing and hide it as well.
361 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
362 afterSpacer->Show(false);
373 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
375 // Go through each of the controls and hide the controls (and spacing) that
376 // have the matched account IDs.
378 int sizerPosition = 0;
380 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
381 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
383 (*CalendarEntryIter)->SetShowAccountStatus(true);
385 if ((*CalendarEntryIter)->GetShowCalendarStatus() == false){
389 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
391 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
392 (*CalendarEntryIter)->Show(true);
394 // Get the spacing and hide it as well.
396 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
397 afterSpacer->Show(true);
408 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
410 // Go through each of the controls and hide the controls (and spacing) that
411 // have the matched account IDs.
413 int sizerPosition = 0;
415 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
416 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
418 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
420 (*CalendarEntryIter)->SetShowCalendarStatus(false);
422 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
423 (*CalendarEntryIter)->Show(false);
425 // Get the spacing and hide it as well.
427 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
428 afterSpacer->Show(false);
439 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
441 // Go through each of the controls and hide the controls (and spacing) that
442 // have the matched account IDs.
444 int sizerPosition = 0;
446 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
447 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
449 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
451 (*CalendarEntryIter)->SetShowCalendarStatus(true);
453 if ((*CalendarEntryIter)->GetShowAccountStatus() == false){
455 // Don't show the calendar entry because the account status
456 // is set to hidden. Continue to the next one.
462 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
463 (*CalendarEntryIter)->Show(true);
465 // Get the spacing and hide it as well.
467 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
468 afterSpacer->Show(true);
479 void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){
481 vector<vector<XCCalendarDayEntry*>::iterator> DeleteEntriesList;
483 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
484 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
486 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
488 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
489 (*CalendarEntryIter)->Show(false);
491 // Get the spacing and hide it as well.
493 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
494 afterSpacer->Show(false);
495 afterSpacer->DetachSizer();
498 afterSpacer = nullptr;
500 delete (*CalendarEntryIter);
501 DeleteEntriesList.push_back(CalendarEntryIter);
510 for (auto DeleteIter : DeleteEntriesList){
511 CalendarEntryList.erase(DeleteIter);
516 void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){
518 vector<vector<XCCalendarDayEntry*>::iterator> DeleteEntriesList;
520 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
521 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
523 if ((*CalendarEntryIter)->GetEventID() == eventData.GetInt()){
525 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
526 (*CalendarEntryIter)->Show(false);
528 // Get the spacing and hide it as well.
530 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
531 afterSpacer->Show(false);
532 afterSpacer->DetachSizer();
535 afterSpacer = nullptr;
537 delete (*CalendarEntryIter);
538 DeleteEntriesList.push_back(CalendarEntryIter);
544 for (auto DeleteIter : DeleteEntriesList){
545 CalendarEntryList.erase(DeleteIter);
553 void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){
555 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
557 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID);
559 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID);
561 newEntry->SetColour(&calendarInfo.calendarColour);
562 newEntry->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
563 newEntry->SetEntryIDs(calendarInfo.accountID, eventInfo->calendarID, eventInfo->eventID);
565 EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
566 wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
568 newEntry->SetAfterSpacer(afterSpacer);
570 // Go through the list of calendar entries to hide by account.
572 for (vector<int>::iterator hideAccountsItem = eventInfo->hideAccountsList.begin();
573 hideAccountsItem != eventInfo->hideAccountsList.end(); hideAccountsItem++){
575 if (*hideAccountsItem = calendarInfo.accountID){
576 newEntry->Show(false);
577 newEntry->GetAfterSpacer()->Show(false);
582 // Go through the list of calendar entries to hide by calendar.
584 for (vector<int>::iterator hideCalendarsItem = eventInfo->hideCalendarsList.begin();
585 hideCalendarsItem != eventInfo->hideCalendarsList.end(); hideCalendarsItem++){
587 if (*hideCalendarsItem == eventInfo->calendarID){
588 newEntry->Show(false);
589 newEntry->GetAfterSpacer()->Show(false);
594 CalendarEntryList.push_back(newEntry);
601 void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){
603 // Go thorugh each of the entries in the day and
606 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
608 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
609 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
611 if ((*CalendarEntryIter)->GetEventID() == eventInfo->eventID){
613 (*CalendarEntryIter)->SetEventName(eventInfo->eventName);
614 (*CalendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
626 void XCCalendarDay::UpdateCalendarColour(wxCommandEvent &colourData){
628 // Go thorugh each of the entries in the day and
631 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
633 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
634 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
636 if ((*CalendarEntryIter)->GetCalendarID() == colourInfo->calendarID){
638 (*CalendarEntryIter)->SetColour(&colourInfo->newColour);
646 int XCCalendarDay::GetCalendarDay(){
652 int XCCalendarDay::GetCalendarMonth(){
654 return calendarMonth;
658 int XCCalendarDay::GetCalendarYear(){