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)
36 EVT_PAINT(XCCalendarDay::PaintFrameEvent)
37 EVT_SIZE(XCCalendarDay::ResizeFrameEvent)
40 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
41 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
42 this->SetMinSize( wxSize( 100,100 ) );
46 wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
47 wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
49 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
50 wxBitmap imgAlertIcon(icons_alert_png, -1);
52 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
53 wxBitmap imgPriorityIcon(icons_priority_png, -1);
55 alertIcon->SetBitmap(imgAlertIcon);
56 highPriorityIcon->SetBitmap(imgPriorityIcon);
58 windowSizer->AddGrowableCol(0);
59 windowSizer->AddGrowableRow(1);
60 windowSizer->SetFlexibleDirection( wxBOTH );
61 windowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
63 numberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
64 numberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
66 topSectionSizer->Add(highPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
67 topSectionSizer->Add(alertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
68 topSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
69 topSectionSizer->Add(numberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
71 // Setup the scrollable section.
74 eventColour.red = 40; eventColour.green = 80; eventColour.blue = 80;
76 eventListFrame->SetSizer(eventListFrameSizer);
78 eventListFrame->SetScrollRate(0,1);
79 eventListFrameSizer->Fit(eventListFrame);
80 eventListFrameSizer->Layout();
81 windowSizer->Fit(this);
83 // Setup the scroll window.
85 mainSectionSizer->Add(eventListFrame, 1, wxGROW | wxALL, 10);
87 windowSizer->Add(topSectionSizer, 1, wxEXPAND, 5);
88 windowSizer->Add(mainSectionSizer, 1, wxEXPAND, 5);
90 this->SetSizer(windowSizer);
93 this->SetBackgroundStyle(wxBG_STYLE_PAINT);
98 // Bind events to the control.
100 Bind(XCCALENDARDAY_DESELECTOTHERENTRIES, &XCCalendarDay::DeselectOthersEvent, this, ID_DESELECTOTHERENTRIES);
101 Bind(XCCALENDARDAY_DESELECTALLENTRIES, &XCCalendarDay::DeselectAllEvent, this, ID_DESELECTALLITEMS);
102 Bind(XCCALENDARDAY_HIDEACCOUNTENTRIES, &XCCalendarDay::HideAccountEntries, this, ID_HIDEENTRIES);
103 Bind(XCCALENDARDAY_SHOWACCOUNTENTRIES, &XCCalendarDay::ShowAccountEntries, this, ID_SHOWENTRIES);
104 Bind(XCCALENDARDAY_HIDECALENDARENTRIES, &XCCalendarDay::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
105 Bind(XCCALENDARDAY_SHOWCALENDARENTRIES, &XCCalendarDay::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
106 Bind(XCCALENDARDAY_DELETECALENDARENTRIES, &XCCalendarDay::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
107 Bind(XCCALENDARDAY_DELETEENTRY, &XCCalendarDay::DeleteCalendarEntry, this, ID_DELETEENTRY);
108 Bind(XCCALENDARDAY_ADDENTRY, &XCCalendarDay::AddCalendarEntry, this, ID_ADDENTRY);
109 Bind(XCCALENDARDAY_UPDATEENTRY, &XCCalendarDay::UpdateCalendarEntry, this, ID_UPDATEENTRY);
110 Bind(XCCALENDARDAY_UPDATECALENDARCOLOUR, &XCCalendarDay::UpdateCalendarColour, this, ID_UPDATECOLOUR);
113 XCCalendarDay::~XCCalendarDay(){
115 // Destory the controls from the widget.
117 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
118 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
120 delete((*calendarEntryIter));
127 delete highPriorityIcon;
128 highPriorityIcon = nullptr;
130 delete eventListFrame;
131 eventListFrame = nullptr;
133 calendarEntryList.clear();
137 void XCCalendarDay::Repaint(){
140 wxPaintDC eventListFrameDC(eventListFrame);
142 // Get the wxSizerItem for the top date and the entries part.
144 wxSizerItem *topSectionSizerItem = windowSizer->GetItem((size_t)0);
145 wxSizerItem *mainSectionSizerItem = windowSizer->GetItem((size_t)1);
146 wxRect topSizer = wxRect(windowSizer->GetPosition(), windowSizer->GetSize());
148 if (isInMonth == true){
150 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
151 dc.SetBrush(wxBrush(wxColor(255,255,255)));
152 dc.DrawRectangle(topSectionSizerItem->GetRect());
153 dc.SetBrush(wxBrush(wxColor(225,225,225)));
154 dc.DrawRectangle(mainSectionSizerItem->GetRect());
155 eventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
156 eventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
157 eventListFrameDC.DrawRectangle(eventListFrame->GetClientRect());
161 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
162 dc.SetBrush(wxBrush(wxColor(185,185,185)));
163 dc.DrawRectangle(topSectionSizerItem->GetRect());
164 dc.SetBrush(wxBrush(wxColor(155,155,155)));
165 dc.DrawRectangle(mainSectionSizerItem->GetRect());
166 eventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
167 eventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
168 eventListFrameDC.DrawRectangle(eventListFrame->GetClientRect());
174 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
180 void XCCalendarDay::UpdateTopIcons(){
182 bool alarmFound = false;
183 bool highPriorityFound = false;
185 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
186 entryIter != calendarEntryList.end(); entryIter++){
188 if ((*entryIter)->GetDisplayAlarm() == true){
194 if ((*entryIter)->GetDisplayHighPriority() == true){
196 highPriorityFound = true;
200 if (alarmFound == true && highPriorityFound == true){
208 alertIcon->Show(alarmFound);
209 highPriorityIcon->Show(highPriorityFound);
213 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &paintEvent)
220 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &sizeEvent)
223 // TODO: Check if window size is less than 120 pixels and if it is,
224 // switch to the small block mode.
226 // Refresh the window.
232 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &deselectEvent)
235 int selectedEntryID = deselectEvent.GetInt();
237 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
238 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
240 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
241 entryIter != calendarEntryList.end(); entryIter++){
243 if ((*entryIter)->GetID() != selectedEntryID){
245 wxPostEvent((*entryIter), deselectEntryEvent);
251 // Send event notification to deselect the other calendar entries.
253 if (this->monthViewPointer != nullptr){
255 wxCommandEvent deselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
256 deselectEvent.SetClientData(this);
257 deselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
258 wxPostEvent(this->monthViewPointer, deselectEvent);
264 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &deselectEvent)
267 int selectedEntryID = deselectEvent.GetInt();
269 wxCommandEvent deselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
270 deselectEntryEvent.SetId(ID_ENTRYDESELECT);
272 for (vector<XCCalendarDayEntry*>::iterator entryIter = calendarEntryList.begin();
273 entryIter != calendarEntryList.end(); entryIter++){
275 wxPostEvent((*entryIter), deselectEntryEvent);
281 void XCCalendarDay::SetupControl(int setupDay, int setupMonth, int setupYear, bool setupIsInMonth, XCCalendarMonthView *monthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
284 this->dataStorage = dataStorage;
288 numberText->SetLabel(wxString::Format("%02i", setupDay));
289 calendarDay = setupDay;
293 calendarMonth = setupMonth;
297 calendarYear = setupYear;
299 // Setup the Is In Month value.
301 isInMonth = setupIsInMonth;
303 // Setup the month view pointer.
305 this->monthViewPointer = monthViewPointer;
307 // Setup the calendar items.
309 CDSEntryList calendarItems = dataStorage->GetEventListByDate(setupYear, setupMonth, setupDay);
311 for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
313 // Get the information about the calendar entry.
315 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
316 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
318 // Setup the calendar entry.
320 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
322 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
323 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
324 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
326 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
327 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
329 newEntry->SetAfterSpacer(afterSpacer);
331 // Go through the list of calendar entries to hide by account.
333 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
334 hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
336 if (*hideAccountsItem == newEntryCalendarInfo.accountID){
337 newEntry->Show(false);
338 newEntry->GetAfterSpacer()->Show(false);
343 // Go through the list of calendar entries to hide by calendar.
345 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
346 hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
348 if (*hideCalendarsItem == newEntryInfo.calendarID){
349 newEntry->Show(false);
350 newEntry->GetAfterSpacer()->Show(false);
355 calendarEntryList.push_back(newEntry);
360 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
362 // Go through each of the controls and hide the controls (and spacing) that
363 // have the matched account IDs.
365 int sizerPosition = 0;
367 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
368 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
370 (*calendarEntryIter)->SetShowAccountStatus(false);
372 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
374 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
375 (*calendarEntryIter)->Show(false);
377 // Get the spacing and hide it as well.
379 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
380 afterSpacer->Show(false);
391 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
393 // Go through each of the controls and hide the controls (and spacing) that
394 // have the matched account IDs.
396 int sizerPosition = 0;
398 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
399 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
401 (*calendarEntryIter)->SetShowAccountStatus(true);
403 if ((*calendarEntryIter)->GetShowCalendarStatus() == false){
407 if ((*calendarEntryIter)->GetAccountID() == accountData.GetInt()){
409 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
410 (*calendarEntryIter)->Show(true);
412 // Get the spacing and hide it as well.
414 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
415 afterSpacer->Show(true);
426 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
428 // Go through each of the controls and hide the controls (and spacing) that
429 // have the matched account IDs.
431 int sizerPosition = 0;
433 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
434 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
436 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
438 (*calendarEntryIter)->SetShowCalendarStatus(false);
440 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
441 (*calendarEntryIter)->Show(false);
443 // Get the spacing and hide it as well.
445 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
446 afterSpacer->Show(false);
457 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
459 // Go through each of the controls and hide the controls (and spacing) that
460 // have the matched account IDs.
462 int sizerPosition = 0;
464 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
465 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
467 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
469 (*calendarEntryIter)->SetShowCalendarStatus(true);
471 if ((*calendarEntryIter)->GetShowAccountStatus() == false){
473 // Don't show the calendar entry because the account status
474 // is set to hidden. Continue to the next one.
480 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
481 (*calendarEntryIter)->Show(true);
483 // Get the spacing and hide it as well.
485 wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
486 afterSpacer->Show(true);
497 void XCCalendarDay::DeleteCalendarEntries(wxCommandEvent &calendarData){
499 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
501 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
502 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
504 if ((*calendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
506 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
507 (*calendarEntryIter)->Show(false);
509 // Get the spacing and hide it as well.
511 /*wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
512 afterSpacer->Show(false);
513 afterSpacer->DetachSizer();
516 afterSpacer = nullptr;*/
518 delete (*calendarEntryIter);
519 deleteEntriesList.push_back(calendarEntryIter);
528 for (auto deleteIter : deleteEntriesList){
529 calendarEntryList.erase(deleteIter);
534 void XCCalendarDay::DeleteCalendarEntry(wxCommandEvent &eventData){
536 vector<vector<XCCalendarDayEntry*>::iterator> deleteEntriesList;
538 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
539 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
541 if ((*calendarEntryIter)->GetEventID() == eventData.GetInt()){
543 wxSizerItem *calendarItem = eventListFrameSizer->GetItem((*calendarEntryIter));
544 (*calendarEntryIter)->Show(false);
546 // Get the spacing and hide it as well.
548 /*wxSizerItem *afterSpacer = (*calendarEntryIter)->GetAfterSpacer();
549 afterSpacer->Show(false);
550 afterSpacer->DetachSizer();
553 afterSpacer = nullptr;*/
555 delete (*calendarEntryIter);
556 deleteEntriesList.push_back(calendarEntryIter);
562 for (auto deleteIter : deleteEntriesList){
563 calendarEntryList.erase(deleteIter);
571 void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){
573 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
575 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID);
577 CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID);
579 newEntry->SetColour(&calendarInfo.calendarColour);
580 newEntry->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
581 newEntry->SetEntryIDs(calendarInfo.accountID, eventInfo->calendarID, eventInfo->eventID);
583 eventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
584 wxSizerItem *afterSpacer = eventListFrameSizer->Add(0, 5, 0, 0, 5);
586 newEntry->SetAfterSpacer(afterSpacer);
588 // Go through the list of calendar entries to hide by account.
590 for (vector<int>::iterator hideAccountsItem = eventInfo->hideAccountsList.begin();
591 hideAccountsItem != eventInfo->hideAccountsList.end(); hideAccountsItem++){
593 if (*hideAccountsItem = calendarInfo.accountID){
594 newEntry->Show(false);
595 newEntry->GetAfterSpacer()->Show(false);
600 // Go through the list of calendar entries to hide by calendar.
602 for (vector<int>::iterator hideCalendarsItem = eventInfo->hideCalendarsList.begin();
603 hideCalendarsItem != eventInfo->hideCalendarsList.end(); hideCalendarsItem++){
605 if (*hideCalendarsItem == eventInfo->calendarID){
606 newEntry->Show(false);
607 newEntry->GetAfterSpacer()->Show(false);
612 calendarEntryList.push_back(newEntry);
619 void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){
621 // Go thorugh each of the entries in the day and
624 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
626 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
627 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
629 if ((*calendarEntryIter)->GetEventID() == eventInfo->eventID){
631 (*calendarEntryIter)->SetEventName(eventInfo->eventName);
632 (*calendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond);
644 void XCCalendarDay::UpdateCalendarColour(wxCommandEvent &colourData){
646 // Go thorugh each of the entries in the day and
649 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
651 for (vector<XCCalendarDayEntry*>::iterator calendarEntryIter = calendarEntryList.begin();
652 calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){
654 if ((*calendarEntryIter)->GetCalendarID() == colourInfo->calendarID){
656 (*calendarEntryIter)->SetColour(&colourInfo->newColour);
664 int XCCalendarDay::GetCalendarDay(){
670 int XCCalendarDay::GetCalendarMonth(){
672 return calendarMonth;
676 int XCCalendarDay::GetCalendarYear(){