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));
116 delete highPriorityIcon;
117 highPriorityIcon = nullptr;
119 delete eventListFrame;
120 eventListFrame = nullptr;
122 calendarEntryList.clear();
126 void XCCalendarDay::Repaint(){
129 wxPaintDC eventListFrameDC(eventListFrame);
131 // Get the wxSizerItem for the top date and the entries part.
133 wxSizerItem *topSectionSizerItem = windowSizer->GetItem((size_t)0);
134 wxSizerItem *mainSectionSizerItem = windowSizer->GetItem((size_t)1);
135 wxRect topSizer = wxRect(windowSizer->GetPosition(), windowSizer->GetSize());
137 if (isInMonth == true){
139 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
140 dc.SetBrush(wxBrush(wxColor(255,255,255)));
141 dc.DrawRectangle(topSectionSizerItem->GetRect());
142 dc.SetBrush(wxBrush(wxColor(225,225,225)));
143 dc.DrawRectangle(mainSectionSizerItem->GetRect());
144 eventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
145 eventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
146 eventListFrameDC.DrawRectangle(eventListFrame->GetClientRect());
150 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
151 dc.SetBrush(wxBrush(wxColor(185,185,185)));
152 dc.DrawRectangle(topSectionSizerItem->GetRect());
153 dc.SetBrush(wxBrush(wxColor(155,155,155)));
154 dc.DrawRectangle(mainSectionSizerItem->GetRect());
155 eventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
156 eventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
157 eventListFrameDC.DrawRectangle(eventListFrame->GetClientRect());
163 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
169 void XCCalendarDay::UpdateTopIcons(){
171 bool alarmFound = false;
172 bool highPriorityFound = false;
174 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
175 entryIter != calendarEntryList.end(); entryIter++){
177 if ((*entryIter)->GetDisplayAlarm() == true){
183 if ((*entryIter)->GetDisplayHighPriority() == true){
185 highPriorityFound = true;
189 if (alarmFound == true && highPriorityFound == true){
197 alertIcon->Show(alarmFound);
198 highPriorityIcon->Show(highPriorityFound);
202 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &paintEvent)
209 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &sizeEvent)
212 // TODO: Check if window size is less than 120 pixels and if it is,
213 // switch to the small block mode.
215 // Refresh the window.
221 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &deselectEvent)
224 int selectedEntryID = deselectEvent.GetInt();
226 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
227 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
229 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
230 entryIter != calendarEntryList.end(); entryIter++){
232 if ((*entryIter)->GetID() != selectedEntryID){
234 wxPostEvent((*entryIter), deselectEntryEvent);
240 // Send event notification to deselect the other calendar entries.
242 if (this->monthViewPointer != nullptr){
244 wxCommandEvent deselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
245 deselectEvent.SetClientData(this);
246 deselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
247 wxPostEvent(this->monthViewPointer, deselectEvent);
253 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &deselectEvent)
256 int selectedEntryID = deselectEvent.GetInt();
258 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
259 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
261 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
262 entryIter != calendarEntryList.end(); entryIter++){
264 wxPostEvent((*entryIter), deselectEntryEvent);
270 void XCCalendarDay::SetupControl(int setupDay, int setupMonth, int setupYear, bool setupIsInMonth, XCCalendarMonthView *monthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
273 this->dataStorage = dataStorage;
277 numberText->SetLabel(wxString::Format("%02i", setupDay));
278 calendarDay = setupDay;
282 calendarMonth = setupMonth;
286 calendarYear = setupYear;
288 // Setup the Is In Month value.
290 isInMonth = setupIsInMonth;
292 // Setup the month view pointer.
294 this->monthViewPointer = monthViewPointer;
296 // Setup the calendar items.
298 CDSEntryList calendarItems = dataStorage->GetEventListByDate(setupYear, setupMonth, setupDay);
300 for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
302 // Get the information about the calendar entry.
304 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
305 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
307 // Setup the calendar entry.
309 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
311 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
312 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
313 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
315 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
316 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
318 newEntry->SetAfterSpacer(afterSpacer);
320 // Go through the list of calendar entries to hide by account.
322 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
323 hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
325 if (*hideAccountsItem == newEntryCalendarInfo.accountID){
326 newEntry->Show(false);
327 newEntry->GetAfterSpacer()->Show(false);
332 // Go through the list of calendar entries to hide by calendar.
334 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
335 hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
337 if (*hideCalendarsItem == newEntryInfo.calendarID){
338 newEntry->Show(false);
339 newEntry->GetAfterSpacer()->Show(false);
344 calendarEntryList.push_back(newEntry);
349 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
351 // Go through each of the controls and hide the controls (and spacing) that
352 // have the matched account IDs.
354 int sizerPosition = 0;
356 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
357 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
359 (*calendarEntryIter)->SetShowAccountStatus(false);
361 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
363 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
364 (*calendarEntryIter)->Show(false);
366 // Get the spacing and hide it as well.
368 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
369 afterSpacer->Show(false);
380 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
382 // Go through each of the controls and hide the controls (and spacing) that
383 // have the matched account IDs.
385 int sizerPosition = 0;
387 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
388 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
390 (*calendarEntryIter)->SetShowAccountStatus(true);
392 if ((*calendarEntryIter)->GetShowCalendarStatus() == false){
396 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
398 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
399 (*calendarEntryIter)->Show(true);
401 // Get the spacing and hide it as well.
403 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
404 afterSpacer->Show(true);
415 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
417 // Go through each of the controls and hide the controls (and spacing) that
418 // have the matched account IDs.
420 int sizerPosition = 0;
422 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
423 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
425 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
427 (*calendarEntryIter)->SetShowCalendarStatus(false);
429 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
430 (*calendarEntryIter)->Show(false);
432 // Get the spacing and hide it as well.
434 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
435 afterSpacer->Show(false);
446 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
448 // Go through each of the controls and hide the controls (and spacing) that
449 // have the matched account IDs.
451 int sizerPosition = 0;
453 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
454 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
456 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
458 (*calendarEntryIter)->SetShowCalendarStatus(true);
460 if ((*calendarEntryIter)->GetShowAccountStatus() == false){
462 // Don't show the calendar entry because the account status
463 // is set to hidden. Continue to the next one.
469 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
470 (*calendarEntryIter)->Show(true);
472 // Get the spacing and hide it as well.
474 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
475 afterSpacer->Show(true);
486 void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){
488 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
490 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
491 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
493 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
495 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
496 (*calendarEntryIter)->Show(false);
498 // Get the spacing and hide it as well.
500 /*wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
501 afterSpacer->Show(false);
502 afterSpacer->DetachSizer();
505 afterSpacer = nullptr;*/
507 delete (*calendarEntryIter);
508 deleteEntriesList.push_back(calendarEntryIter);
517 for (auto deleteIter : deleteEntriesList){
518 calendarEntryList.erase(deleteIter);
523 void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){
525 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
527 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
528 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
530 if ((*calendarEntryIter)->GetEventID() == eventData.GetInt()){
532 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
533 (*calendarEntryIter)->Show(false);
535 // Get the spacing and hide it as well.
537 /*wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
538 afterSpacer->Show(false);
539 afterSpacer->DetachSizer();
542 afterSpacer = nullptr;*/
544 delete (*calendarEntryIter);
545 deleteEntriesList.push_back(calendarEntryIter);
551 for (auto deleteIter : deleteEntriesList){
552 calendarEntryList.erase(deleteIter);
560 void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){
562 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
564 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID);
566 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID);
568 newEntry->SetColour(&calendarInfo.calendarColour);
569 newEntry->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
570 newEntry->SetEntryIDs(calendarInfo.accountID, eventInfo->calendarID, eventInfo->eventID);
572 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
573 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
575 newEntry->SetAfterSpacer(afterSpacer);
577 // Go through the list of calendar entries to hide by account.
579 for (vector<int>::iterator hideAccountsItem = eventInfo->hideAccountsList.begin();
580 hideAccountsItem != eventInfo->hideAccountsList.end(); hideAccountsItem++){
582 if (*hideAccountsItem = calendarInfo.accountID){
583 newEntry->Show(false);
584 newEntry->GetAfterSpacer()->Show(false);
589 // Go through the list of calendar entries to hide by calendar.
591 for (vector<int>::iterator hideCalendarsItem = eventInfo->hideCalendarsList.begin();
592 hideCalendarsItem != eventInfo->hideCalendarsList.end(); hideCalendarsItem++){
594 if (*hideCalendarsItem == eventInfo->calendarID){
595 newEntry->Show(false);
596 newEntry->GetAfterSpacer()->Show(false);
601 calendarEntryList.push_back(newEntry);
608 void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){
610 // Go thorugh each of the entries in the day and
613 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
615 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
616 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
618 if ((*calendarEntryIter)->GetEventID() == eventInfo->eventID){
620 (*calendarEntryIter)->SetEventName(eventInfo->eventName);
621 (*calendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
633 void XCCalendarDay::UpdateCalendarColour(wxCommandEvent &colourData){
635 // Go thorugh each of the entries in the day and
638 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
640 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
641 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
643 if ((*calendarEntryIter)->GetCalendarID() == colourInfo->calendarID){
645 (*calendarEntryIter)->SetColour(&colourInfo->newColour);
653 int XCCalendarDay::GetCalendarDay(){
659 int XCCalendarDay::GetCalendarMonth(){
661 return calendarMonth;
665 int XCCalendarDay::GetCalendarYear(){