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(){