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 wxDEFINE_EVENT(XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEvent);
24 wxDEFINE_EVENT(XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEvent);
25 wxDEFINE_EVENT(XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEvent);
26 wxDEFINE_EVENT(XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEvent);
27 wxDEFINE_EVENT(XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEvent);
28 wxDEFINE_EVENT(XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEvent);
29 wxDEFINE_EVENT(XCCALENDARDAY_DELETECALENDARENTRIES, wxCommandEvent);
30 wxDEFINE_EVENT(XCCALENDARDAY_DELETEENTRY, wxCommandEvent);
31 wxDEFINE_EVENT(XCCALENDARDAY_ADDENTRY, wxCommandEvent);
32 wxDEFINE_EVENT(XCCALENDARDAY_UPDATEENTRY, wxCommandEvent);
33 wxDEFINE_EVENT(XCCALENDARDAY_UPDATECALENDARCOLOUR, wxCommandEvent);
35 BEGIN_EVENT_TABLE(XCCalendarDay, wxPanel)
38 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
39 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
40 this->SetMinSize( wxSize( 100,100 ) );
42 // Setup the top panel.
44 topPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), wxSize(50, 40), wxTAB_TRAVERSAL);
45 mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), wxSize(200, 200), wxTAB_TRAVERSAL);
49 highPriorityIcon = new wxStaticBitmap(topPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0);
50 alertIcon = new wxStaticBitmap(topPanel, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize(32,32), 0);
52 wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
53 wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
55 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
56 wxBitmap imgAlertIcon(icons_alert_png, -1);
58 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
59 wxBitmap imgPriorityIcon(icons_priority_png, -1);
61 alertIcon->SetBitmap(imgAlertIcon);
62 highPriorityIcon->SetBitmap(imgPriorityIcon);
64 numberText = new wxStaticText(topPanel, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
65 numberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
67 topSectionSizer->Add(highPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
68 topSectionSizer->Add(alertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
69 topSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
70 topSectionSizer->Add(numberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
72 // Setup the scrollable section.
74 eventListFrame = new wxScrolledWindow(mainPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL);
77 eventColour.red = 40; eventColour.green = 80; eventColour.blue = 80;
79 eventListFrame->SetSizer(eventListFrameSizer);
81 eventListFrame->SetScrollRate(0,1);
82 eventListFrameSizer->Fit(eventListFrame);
83 eventListFrameSizer->Layout();
85 // Setup the scroll window.
87 mainSectionSizer->Add(eventListFrame, 1, wxGROW | wxALL, 5);
89 topPanel->SetSizer(topSectionSizer);
90 mainPanel->SetSizer(mainSectionSizer);
92 windowSizer->Add(topPanel, 1, wxEXPAND, 0);
93 windowSizer->Add(mainPanel, 1, wxEXPAND, 0);
95 this->SetSizer(windowSizer);
102 // Bind events to the control.
104 Bind(XCCALENDARDAY_DESELECTOTHERENTRIES, &XCCalendarDay::DeselectOthersEvent, this, ID_DESELECTOTHERENTRIES);
105 Bind(XCCALENDARDAY_DESELECTALLENTRIES, &XCCalendarDay::DeselectAllEvent, this, ID_DESELECTALLITEMS);
106 Bind(XCCALENDARDAY_HIDEACCOUNTENTRIES, &XCCalendarDay::HideAccountEntries, this, ID_HIDEENTRIES);
107 Bind(XCCALENDARDAY_SHOWACCOUNTENTRIES, &XCCalendarDay::ShowAccountEntries, this, ID_SHOWENTRIES);
108 Bind(XCCALENDARDAY_HIDECALENDARENTRIES, &XCCalendarDay::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
109 Bind(XCCALENDARDAY_SHOWCALENDARENTRIES, &XCCalendarDay::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
110 Bind(XCCALENDARDAY_DELETECALENDARENTRIES, &XCCalendarDay::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
111 Bind(XCCALENDARDAY_DELETEENTRY, &XCCalendarDay::DeleteCalendarEntry, this, ID_DELETEENTRY);
112 Bind(XCCALENDARDAY_ADDENTRY, &XCCalendarDay::AddCalendarEntry, this, ID_ADDENTRY);
113 Bind(XCCALENDARDAY_UPDATEENTRY, &XCCalendarDay::UpdateCalendarEntry, this, ID_UPDATEENTRY);
114 Bind(XCCALENDARDAY_UPDATECALENDARCOLOUR, &XCCalendarDay::UpdateCalendarColour, this, ID_UPDATECOLOUR);
117 XCCalendarDay::~XCCalendarDay(){
119 // Destory the controls from the widget.
121 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
122 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
124 delete((*calendarEntryIter));
131 delete highPriorityIcon;
132 highPriorityIcon = nullptr;
134 delete eventListFrame;
135 eventListFrame = nullptr;
137 calendarEntryList.clear();
141 void XCCalendarDay::UpdateTopIcons(){
143 bool alarmFound = false;
144 bool highPriorityFound = false;
146 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
147 entryIter != calendarEntryList.end(); entryIter++){
149 if ((*entryIter)->GetDisplayAlarm() == true){
155 if ((*entryIter)->GetDisplayHighPriority() == true){
157 highPriorityFound = true;
161 if (alarmFound == true && highPriorityFound == true){
169 alertIcon->Show(alarmFound);
170 highPriorityIcon->Show(highPriorityFound);
174 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &sizeEvent)
177 // TODO: Check if window size is less than 120 pixels and if it is,
178 // switch to the small block mode.
180 // Refresh the window.
184 mainPanel->Refresh();
185 topSectionSizer->Layout();
186 mainSectionSizer->Layout();
187 windowSizer->Layout();
191 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &deselectEvent)
194 int selectedEntryID = deselectEvent.GetInt();
196 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
197 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
199 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
200 entryIter != calendarEntryList.end(); entryIter++){
202 if ((*entryIter)->GetID() != selectedEntryID){
204 wxPostEvent((*entryIter), deselectEntryEvent);
210 // Send event notification to deselect the other calendar entries.
212 if (this->monthViewPointer != nullptr){
214 wxCommandEvent deselectMonthEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
215 deselectMonthEvent.SetClientData(this);
216 deselectMonthEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
217 wxPostEvent(this->monthViewPointer, deselectMonthEvent);
223 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &deselectEvent)
226 int selectedEntryID = deselectEvent.GetInt();
228 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
229 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
231 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
232 entryIter != calendarEntryList.end(); entryIter++){
234 wxPostEvent((*entryIter), deselectEntryEvent);
240 void XCCalendarDay::SetupControl(int setupDay, int setupMonth, int setupYear, bool setupIsInMonth, XCCalendarMonthView *monthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
243 this->dataStorage = dataStorage;
247 numberText->SetLabel(wxString::Format("%02i", setupDay));
248 calendarDay = setupDay;
252 calendarMonth = setupMonth;
256 calendarYear = setupYear;
258 // Setup the Is In Month value.
260 isInMonth = setupIsInMonth;
263 topPanel->SetBackgroundColour(wxColor(255,255,255));
264 mainPanel->SetBackgroundColour(wxColor(225,225,225));
265 eventListFrame->SetBackgroundColour(wxColor(225,225,225));
269 topPanel->SetBackgroundColour(wxColor(185,185,185));
270 mainPanel->SetBackgroundColour(wxColor(155,155,155));
271 eventListFrame->SetBackgroundColour(wxColor(155,155,155));
274 // Setup the month view pointer.
276 this->monthViewPointer = monthViewPointer;
278 // Setup the calendar items.
280 CDSEntryList calendarItems = dataStorage->GetEventListByDate(setupYear, setupMonth, setupDay);
282 for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
284 // Get the information about the calendar entry.
286 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
287 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
289 // Setup the calendar entry.
291 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
293 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
294 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
295 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
297 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
298 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
300 newEntry->SetAfterSpacer(afterSpacer);
302 // Go through the list of calendar entries to hide by account.
304 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
305 hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
307 if (*hideAccountsItem == newEntryCalendarInfo.accountID){
308 newEntry->Show(false);
309 newEntry->GetAfterSpacer()->Show(false);
314 // Go through the list of calendar entries to hide by calendar.
316 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
317 hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
319 if (*hideCalendarsItem == newEntryInfo.calendarID){
320 newEntry->Show(false);
321 newEntry->GetAfterSpacer()->Show(false);
326 calendarEntryList.push_back(newEntry);
331 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
333 // Go through each of the controls and hide the controls (and spacing) that
334 // have the matched account IDs.
336 int sizerPosition = 0;
338 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
339 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
341 (*calendarEntryIter)->SetShowAccountStatus(false);
343 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
345 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
346 (*calendarEntryIter)->Show(false);
348 // Get the spacing and hide it as well.
350 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
351 afterSpacer->Show(false);
361 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
363 // Go through each of the controls and hide the controls (and spacing) that
364 // have the matched account IDs.
366 int sizerPosition = 0;
368 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
369 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
371 (*calendarEntryIter)->SetShowAccountStatus(true);
373 if ((*calendarEntryIter)->GetShowCalendarStatus() == false){
377 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
379 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
380 (*calendarEntryIter)->Show(true);
382 // Get the spacing and hide it as well.
384 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
385 afterSpacer->Show(true);
395 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
397 // Go through each of the controls and hide the controls (and spacing) that
398 // have the matched account IDs.
400 int sizerPosition = 0;
402 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
403 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
405 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
407 (*calendarEntryIter)->SetShowCalendarStatus(false);
409 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
410 (*calendarEntryIter)->Show(false);
412 // Get the spacing and hide it as well.
414 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
415 afterSpacer->Show(false);
425 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
427 // Go through each of the controls and hide the controls (and spacing) that
428 // have the matched account IDs.
430 int sizerPosition = 0;
432 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
433 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
435 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
437 (*calendarEntryIter)->SetShowCalendarStatus(true);
439 if ((*calendarEntryIter)->GetShowAccountStatus() == false){
441 // Don't show the calendar entry because the account status
442 // is set to hidden. Continue to the next one.
448 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
449 (*calendarEntryIter)->Show(true);
451 // Get the spacing and hide it as well.
453 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
454 afterSpacer->Show(true);
464 void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){
466 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
468 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
469 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
471 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
473 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
474 (*calendarEntryIter)->Show(false);
476 // Get the spacing and hide it as well.
478 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
479 afterSpacer->Show(false);
482 afterSpacer = nullptr;
484 delete (*calendarEntryIter);
485 deleteEntriesList.push_back(calendarEntryIter);
493 eventListFrame->Layout();
494 eventListFrameSizer->Layout();
496 for (auto deleteIter : deleteEntriesList){
497 calendarEntryList.erase(deleteIter);
502 void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){
504 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
506 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
507 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
509 if ((*calendarEntryIter)->GetEventID() == eventData.GetInt()){
511 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
512 (*calendarEntryIter)->Show(false);
514 // Get the spacing and hide it as well.
516 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
517 afterSpacer->Show(false);
519 delete (*calendarEntryIter);
520 deleteEntriesList.push_back(calendarEntryIter);
526 for (auto deleteIter : deleteEntriesList){
527 calendarEntryList.erase(deleteIter);
532 eventListFrame->Layout();
533 eventListFrameSizer->Layout();
537 void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){
539 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
541 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID);
543 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID);
545 newEntry->SetColour(&calendarInfo.calendarColour);
546 newEntry->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
547 newEntry->SetEntryIDs(calendarInfo.accountID, eventInfo->calendarID, eventInfo->eventID);
549 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
550 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
552 newEntry->SetAfterSpacer(afterSpacer);
554 // Go through the list of calendar entries to hide by account.
556 for (vector<int>::iterator hideAccountsItem = eventInfo->hideAccountsList.begin();
557 hideAccountsItem != eventInfo->hideAccountsList.end(); hideAccountsItem++){
559 if (*hideAccountsItem = calendarInfo.accountID){
560 newEntry->Show(false);
561 newEntry->GetAfterSpacer()->Show(false);
566 // Go through the list of calendar entries to hide by calendar.
568 for (vector<int>::iterator hideCalendarsItem = eventInfo->hideCalendarsList.begin();
569 hideCalendarsItem != eventInfo->hideCalendarsList.end(); hideCalendarsItem++){
571 if (*hideCalendarsItem == eventInfo->calendarID){
572 newEntry->Show(false);
573 newEntry->GetAfterSpacer()->Show(false);
578 calendarEntryList.push_back(newEntry);
582 eventListFrame->Layout();
583 eventListFrameSizer->Layout();
587 void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){
589 // Go thorugh each of the entries in the day and
592 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
594 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
595 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
597 if ((*calendarEntryIter)->GetEventID() == eventInfo->eventID){
599 (*calendarEntryIter)->SetEventName(eventInfo->eventName);
600 (*calendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
612 void XCCalendarDay::UpdateCalendarColour(wxCommandEvent &colourData){
614 // Go thorugh each of the entries in the day and
617 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
619 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
620 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
622 if ((*calendarEntryIter)->GetCalendarID() == colourInfo->calendarID){
624 (*calendarEntryIter)->SetColour(&colourInfo->newColour);
632 int XCCalendarDay::GetCalendarDay(){
638 int XCCalendarDay::GetCalendarMonth(){
640 return calendarMonth;
644 int XCCalendarDay::GetCalendarYear(){