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 Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
32 Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
34 this->SetMinSize( wxSize( 100,100 ) );
38 wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
39 wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
41 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
42 wxBitmap imgAlertIcon(icons_alert_png, -1);
44 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
45 wxBitmap imgPriorityIcon(icons_priority_png, -1);
47 AlertIcon->SetBitmap(imgAlertIcon);
48 HighPriorityIcon->SetBitmap(imgPriorityIcon);
50 WindowSizer->AddGrowableCol(0);
51 WindowSizer->AddGrowableRow(1);
52 WindowSizer->SetFlexibleDirection( wxBOTH );
53 WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
55 NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
56 NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
58 TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
59 TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
60 TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
61 TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
63 // Setup the scrollable section.
66 EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
68 EventListFrame->SetSizer(EventListFrameSizer);
69 /*CalendarEntry1->SetColour(&EventColour);
70 CalendarEntry1->SetDisplayAlarm(false);
71 CalendarEntry1->SetDisplayHighPriority(false);
72 EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
73 EventListFrameSizer->Add(0, 5, 0, 0, 5);
75 EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
76 CalendarEntry2->SetColour(&EventColour);
77 CalendarEntry2->SetDisplayAlarm(true);
78 CalendarEntry2->SetDisplayHighPriority(false);
79 EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
80 EventListFrameSizer->Add(0, 5, 0, 0, 5);
82 EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
83 CalendarEntry3->SetColour(&EventColour);
84 CalendarEntry3->SetDisplayAlarm(false);
85 CalendarEntry3->SetDisplayHighPriority(false);
86 EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
87 EventListFrameSizer->Add(0, 5, 0, 0, 5);
89 EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
90 CalendarEntry4->SetColour(&EventColour);
91 CalendarEntry4->SetDisplayAlarm(false);
92 CalendarEntry4->SetDisplayHighPriority(false);
93 EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
94 EventListFrameSizer->Add(0, 5, 0, 0, 5);
96 EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
97 EventListFrameSizer->Add(0, 5, 0, 0, 5);
98 EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
99 EventListFrameSizer->Add(0, 5, 0, 0, 5);
100 EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
101 EventListFrameSizer->Add(0, 5, 0, 0, 5);
102 EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
103 EventListFrameSizer->Add(0, 5, 0, 0, 5);
104 EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
105 EventListFrameSizer->Add(0, 5, 0, 0, 5);
106 EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);*/
108 EventListFrame->SetScrollRate(0,1);
109 //EventListFrameSizer->FitInside(EventListFrame);
110 EventListFrameSizer->Fit(EventListFrame);
111 EventListFrameSizer->Layout();
112 WindowSizer->Fit(this);
114 // Setup the scroll window.
116 WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
117 WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
118 MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
120 this->SetSizer(WindowSizer);
123 this->SetBackgroundStyle(wxBG_STYLE_PAINT);
124 this->Centre(wxBOTH);
126 /*CalendarEntryList.push_back(CalendarEntry1);
127 CalendarEntryList.push_back(CalendarEntry2);
128 CalendarEntryList.push_back(CalendarEntry3);
129 CalendarEntryList.push_back(CalendarEntry4);
130 CalendarEntryList.push_back(CalendarEntry5);
131 CalendarEntryList.push_back(CalendarEntry6);
132 CalendarEntryList.push_back(CalendarEntry7);
133 CalendarEntryList.push_back(CalendarEntry8);
134 CalendarEntryList.push_back(CalendarEntry9);
135 CalendarEntryList.push_back(CalendarEntry10);*/
141 XCCalendarDay::~XCCalendarDay(){
143 // Destory the controls from the widget.
147 void XCCalendarDay::Repaint(){
150 wxPaintDC EventListFrameDC(EventListFrame);
152 // Get the wxSizerItem for the top date and the entries part.
154 wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
155 wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
156 wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
158 if (IsInMonth == true){
160 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
161 dc.SetBrush(wxBrush(wxColor(255,255,255)));
162 dc.DrawRectangle(TopSectionSizerItem->GetRect());
163 dc.SetBrush(wxBrush(wxColor(225,225,225)));
164 dc.DrawRectangle(MainSectionSizerItem->GetRect());
165 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
166 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
167 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
171 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
172 dc.SetBrush(wxBrush(wxColor(185,185,185)));
173 dc.DrawRectangle(TopSectionSizerItem->GetRect());
174 dc.SetBrush(wxBrush(wxColor(155,155,155)));
175 dc.DrawRectangle(MainSectionSizerItem->GetRect());
176 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
177 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
178 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
184 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
190 void XCCalendarDay::UpdateTopIcons(){
192 bool AlarmFound = false;
193 bool HighPriorityFound = false;
195 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
196 EntryIter != CalendarEntryList.end(); EntryIter++){
198 if ((*EntryIter)->GetDisplayAlarm() == true){
204 if ((*EntryIter)->GetDisplayHighPriority() == true){
206 HighPriorityFound = true;
210 if (AlarmFound == true && HighPriorityFound == true){
218 AlertIcon->Show(AlarmFound);
219 HighPriorityIcon->Show(HighPriorityFound);
223 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
230 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
233 // TODO: Check if window size is less than 120 pixels and if it is,
234 // switch to the small block mode.
236 // Refresh the window.
242 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
245 int SelectedEntryID = DeselectEvent.GetInt();
247 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
249 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
250 EntryIter != CalendarEntryList.end(); EntryIter++){
252 if ((*EntryIter)->GetID() != SelectedEntryID){
254 wxPostEvent((*EntryIter), DeselectEntryEvent);
260 // Send event notification to deselect the other calendar entries.
262 if (this->MonthViewPointer != nullptr){
264 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
265 DeselectEvent.SetClientData(this);
266 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
267 wxPostEvent(this->MonthViewPointer, DeselectEvent);
273 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
276 int SelectedEntryID = DeselectEvent.GetInt();
278 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
280 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
281 EntryIter != CalendarEntryList.end(); EntryIter++){
283 wxPostEvent((*EntryIter), DeselectEntryEvent);
289 void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
294 NumberText->SetLabel(wxString::Format("%02i", SetupDay));
300 // Setup the Is In Month value.
302 IsInMonth = SetupIsInMonth;
304 // Setup the month view pointer.
306 this->MonthViewPointer = MonthViewPointer;