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 ) );
36 AlertIconBitmap.LoadFile("AlertIcon-32.png", wxBITMAP_DEFAULT_TYPE);
37 PriorityIconBitmap.LoadFile("PriorityIcon-32.png", wxBITMAP_DEFAULT_TYPE);
39 AlertIcon->SetBitmap(AlertIconBitmap);
40 HighPriorityIcon->SetBitmap(PriorityIconBitmap);
42 WindowSizer->AddGrowableCol(0);
43 WindowSizer->AddGrowableRow(1);
44 WindowSizer->SetFlexibleDirection( wxBOTH );
45 WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
47 NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
48 NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
50 TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
51 TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
52 TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
53 TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
55 // Setup the scrollable section.
58 EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
60 EventListFrame->SetSizer(EventListFrameSizer);
61 CalendarEntry1->SetColour(&EventColour);
62 CalendarEntry1->SetDisplayAlarm(false);
63 CalendarEntry1->SetDisplayHighPriority(false);
64 EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
65 EventListFrameSizer->Add(0, 5, 0, 0, 5);
67 EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
68 CalendarEntry2->SetColour(&EventColour);
69 CalendarEntry2->SetDisplayAlarm(true);
70 CalendarEntry2->SetDisplayHighPriority(false);
71 EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
72 EventListFrameSizer->Add(0, 5, 0, 0, 5);
74 EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
75 CalendarEntry3->SetColour(&EventColour);
76 CalendarEntry3->SetDisplayAlarm(false);
77 CalendarEntry3->SetDisplayHighPriority(false);
78 EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
79 EventListFrameSizer->Add(0, 5, 0, 0, 5);
81 EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
82 CalendarEntry4->SetColour(&EventColour);
83 CalendarEntry4->SetDisplayAlarm(false);
84 CalendarEntry4->SetDisplayHighPriority(false);
85 EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
86 EventListFrameSizer->Add(0, 5, 0, 0, 5);
88 EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
89 EventListFrameSizer->Add(0, 5, 0, 0, 5);
90 EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
91 EventListFrameSizer->Add(0, 5, 0, 0, 5);
92 EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
93 EventListFrameSizer->Add(0, 5, 0, 0, 5);
94 EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
95 EventListFrameSizer->Add(0, 5, 0, 0, 5);
96 EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
97 EventListFrameSizer->Add(0, 5, 0, 0, 5);
98 EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);
100 EventListFrame->SetScrollRate(0,1);
101 //EventListFrameSizer->FitInside(EventListFrame);
102 EventListFrameSizer->Fit(EventListFrame);
103 EventListFrameSizer->Layout();
104 WindowSizer->Fit(this);
106 // Setup the scroll window.
108 WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
109 WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
110 MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
112 this->SetSizer(WindowSizer);
115 this->SetBackgroundStyle(wxBG_STYLE_PAINT);
116 this->Centre(wxBOTH);
118 CalendarEntryList.push_back(CalendarEntry1);
119 CalendarEntryList.push_back(CalendarEntry2);
120 CalendarEntryList.push_back(CalendarEntry3);
121 CalendarEntryList.push_back(CalendarEntry4);
122 CalendarEntryList.push_back(CalendarEntry5);
123 CalendarEntryList.push_back(CalendarEntry6);
124 CalendarEntryList.push_back(CalendarEntry7);
125 CalendarEntryList.push_back(CalendarEntry8);
126 CalendarEntryList.push_back(CalendarEntry9);
127 CalendarEntryList.push_back(CalendarEntry10);
133 XCCalendarDay::~XCCalendarDay(){
135 // Destory the controls from the widget.
139 void XCCalendarDay::Repaint(){
142 wxPaintDC EventListFrameDC(EventListFrame);
144 // Get the wxSizerItem for the top date and the entries part.
146 wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
147 wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
148 wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
150 if (IsInMonth == true){
152 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
153 dc.SetBrush(wxBrush(wxColor(255,255,255)));
154 dc.DrawRectangle(TopSectionSizerItem->GetRect());
155 dc.SetBrush(wxBrush(wxColor(225,225,225)));
156 dc.DrawRectangle(MainSectionSizerItem->GetRect());
157 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
158 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
159 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
163 dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
164 dc.SetBrush(wxBrush(wxColor(185,185,185)));
165 dc.DrawRectangle(TopSectionSizerItem->GetRect());
166 dc.SetBrush(wxBrush(wxColor(155,155,155)));
167 dc.DrawRectangle(MainSectionSizerItem->GetRect());
168 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
169 EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
170 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
176 //dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
182 void XCCalendarDay::UpdateTopIcons(){
184 bool AlarmFound = false;
185 bool HighPriorityFound = false;
187 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
188 EntryIter != CalendarEntryList.end(); EntryIter++){
190 if ((*EntryIter)->GetDisplayAlarm() == true){
196 if ((*EntryIter)->GetDisplayHighPriority() == true){
198 HighPriorityFound = true;
202 if (AlarmFound == true && HighPriorityFound == true){
210 AlertIcon->Show(AlarmFound);
211 HighPriorityIcon->Show(HighPriorityFound);
215 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
222 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
225 // TODO: Check if window size is less than 120 pixels and if it is,
226 // switch to the small block mode.
228 // Refresh the window.
234 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
237 int SelectedEntryID = DeselectEvent.GetInt();
239 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
241 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
242 EntryIter != CalendarEntryList.end(); EntryIter++){
244 if ((*EntryIter)->GetID() != SelectedEntryID){
246 wxPostEvent((*EntryIter), DeselectEntryEvent);
252 // Send event notification to deselect the other calendar entries.
254 if (this->MonthViewPointer != nullptr){
256 wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
257 DeselectEvent.SetClientData(this);
258 DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
259 wxPostEvent(this->MonthViewPointer, DeselectEvent);
265 void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
268 int SelectedEntryID = DeselectEvent.GetInt();
270 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
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)
286 NumberText->SetLabel(wxString::Format("%02i", SetupDay));
292 // Setup the Is In Month value.
294 IsInMonth = SetupIsInMonth;
296 // Setup the month view pointer.
298 this->MonthViewPointer = MonthViewPointer;