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));
97 XCCalendarDay::~XCCalendarDay(){
99 // Destory the controls from the widget.
101 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
102 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
104 delete((*CalendarEntryIter));
108 CalendarEntryList.clear();
114 void XCCalendarDay::Repaint(){
117 wxPaintDC EventListFrameDC(EventListFrame);
119 // Get the wxSizerItem for the top date and the entries part.
121 wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
122 wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
123 wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
125 if (IsInMonth == true){
127 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
128 dc.SetBrush(wxBrush(wxColor(255,255,255)));
129 dc.DrawRectangle(TopSectionSizerItem->GetRect());
130 dc.SetBrush(wxBrush(wxColor(225,225,225)));
131 dc.DrawRectangle(MainSectionSizerItem->GetRect());
132 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
133 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
134 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
138 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
139 dc.SetBrush(wxBrush(wxColor(185,185,185)));
140 dc.DrawRectangle(TopSectionSizerItem->GetRect());
141 dc.SetBrush(wxBrush(wxColor(155,155,155)));
142 dc.DrawRectangle(MainSectionSizerItem->GetRect());
143 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
144 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
145 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
151 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
157 void XCCalendarDay::UpdateTopIcons(){
159 bool AlarmFound = false;
160 bool HighPriorityFound = false;
162 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
163 EntryIter != CalendarEntryList.end(); EntryIter++){
165 if ((*EntryIter)->GetDisplayAlarm() == true){
171 if ((*EntryIter)->GetDisplayHighPriority() == true){
173 HighPriorityFound = true;
177 if (AlarmFound == true && HighPriorityFound == true){
185 AlertIcon->Show(AlarmFound);
186 HighPriorityIcon->Show(HighPriorityFound);
190 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
197 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
200 // TODO: Check if window size is less than 120 pixels and if it is,
201 // switch to the small block mode.
203 // Refresh the window.
209 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
212 int SelectedEntryID = DeselectEvent.GetInt();
214 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
215 DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
217 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
218 EntryIter != CalendarEntryList.end(); EntryIter++){
220 if ((*EntryIter)->GetID() != SelectedEntryID){
222 wxPostEvent((*EntryIter), DeselectEntryEvent);
228 // Send event notification to deselect the other calendar entries.
230 if (this->MonthViewPointer != nullptr){
232 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
233 DeselectEvent.SetClientData(this);
234 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
235 wxPostEvent(this->MonthViewPointer, DeselectEvent);
241 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
244 int SelectedEntryID = DeselectEvent.GetInt();
246 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
247 DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
249 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
250 EntryIter != CalendarEntryList.end(); EntryIter++){
252 wxPostEvent((*EntryIter), DeselectEntryEvent);
258 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, vector<int> *hideAccounts, vector<int> *hideCalendars)
263 NumberText->SetLabel(wxString::Format("%02i", SetupDay));
264 calendarDay = SetupDay;
268 calendarMonth = SetupMonth;
272 calendarYear = SetupYear;
274 // Setup the Is In Month value.
276 IsInMonth = SetupIsInMonth;
278 // Setup the month view pointer.
280 this->MonthViewPointer = MonthViewPointer;
282 // Setup the calendar items.
284 CDSEntryList calendarItems = dataStorage->GetEventListByDate(SetupYear, SetupMonth, SetupDay);
286 for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
288 // Get the information about the calendar entry.
290 CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
291 CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
293 // Setup the calendar entry.
295 XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
297 newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
298 newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
299 newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
301 EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
302 wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
304 newEntry->SetAfterSpacer(afterSpacer);
306 // Go through the list of calendar entries to hide by account.
308 for (vector<int>::iterator hideAccountsItem = hideAccounts->begin();
309 hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
311 if (*hideAccountsItem = newEntryCalendarInfo.accountID){
312 newEntry->Show(false);
313 newEntry->GetAfterSpacer()->Show(false);
318 // Go through the list of calendar entries to hide by calendar.
320 for (vector<int>::iterator hideCalendarsItem = hideCalendars->begin();
321 hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
323 if (*hideCalendarsItem == newEntryInfo.calendarID){
324 newEntry->Show(false);
325 newEntry->GetAfterSpacer()->Show(false);
330 CalendarEntryList.push_back(newEntry);
335 void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
337 // Go through each of the controls and hide the controls (and spacing) that
338 // have the matched account IDs.
340 int sizerPosition = 0;
342 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
343 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
345 (*CalendarEntryIter)->SetShowAccountStatus(false);
347 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
349 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
350 (*CalendarEntryIter)->Show(false);
352 // Get the spacing and hide it as well.
354 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
355 afterSpacer->Show(false);
366 void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
368 // Go through each of the controls and hide the controls (and spacing) that
369 // have the matched account IDs.
371 int sizerPosition = 0;
373 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
374 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
376 (*CalendarEntryIter)->SetShowAccountStatus(true);
378 if ((*CalendarEntryIter)->GetShowCalendarStatus() == false){
382 if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
384 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
385 (*CalendarEntryIter)->Show(true);
387 // Get the spacing and hide it as well.
389 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
390 afterSpacer->Show(true);
401 void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
403 // Go through each of the controls and hide the controls (and spacing) that
404 // have the matched account IDs.
406 int sizerPosition = 0;
408 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
409 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
411 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
413 (*CalendarEntryIter)->SetShowCalendarStatus(false);
415 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
416 (*CalendarEntryIter)->Show(false);
418 // Get the spacing and hide it as well.
420 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
421 afterSpacer->Show(false);
432 void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
434 // Go through each of the controls and hide the controls (and spacing) that
435 // have the matched account IDs.
437 int sizerPosition = 0;
439 for (vector<XCCalendarDayEntry*>::iterator CalendarEntryIter = CalendarEntryList.begin();
440 CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
442 if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
444 (*CalendarEntryIter)->SetShowCalendarStatus(true);
446 if ((*CalendarEntryIter)->GetShowAccountStatus() == false){
448 // Don't show the calendar entry because the account status
449 // is set to hidden. Continue to the next one.
455 wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
456 (*CalendarEntryIter)->Show(true);
458 // Get the spacing and hide it as well.
460 wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
461 afterSpacer->Show(true);