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)
26 //EVT_COMMAND(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, XCCalendarDay::DeselectOthersEvent)
29 XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
30 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
32 Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
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(){
143 // Get the wxSizerItem for the top date and the entries part.
145 wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
146 wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
147 wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
149 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
150 dc.DrawRectangle(TopSectionSizerItem->GetRect());
151 dc.SetBrush(wxBrush(wxColor(225,225,225)));
152 dc.DrawRectangle(MainSectionSizerItem->GetRect());
158 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
160 wxPaintDC EventListFrameDC(EventListFrame);
161 EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
162 EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
163 EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
167 void XCCalendarDay::UpdateTopIcons(){
169 bool AlarmFound = false;
170 bool HighPriorityFound = false;
172 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
173 EntryIter != CalendarEntryList.end(); EntryIter++){
175 if ((*EntryIter)->GetDisplayAlarm() == true){
181 if ((*EntryIter)->GetDisplayHighPriority() == true){
183 HighPriorityFound = true;
187 if (AlarmFound == true && HighPriorityFound == true){
195 AlertIcon->Show(AlarmFound);
196 HighPriorityIcon->Show(HighPriorityFound);
200 void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
207 void XCCalendarDay::ResizeFrameEvent(wxSizeEvent &SizeEvent)
210 // TODO: Check if window size is less than 120 pixels and if it is,
211 // switch to the small block mode.
213 // Refresh the window.
219 void XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
222 int SelectedEntryID = DeselectEvent.GetInt();
224 wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
226 for (vector<XCCalendarDayEntry*>::iterator EntryIter = CalendarEntryList.begin();
227 EntryIter != CalendarEntryList.end(); EntryIter++){
229 if ((*EntryIter)->GetID() != SelectedEntryID){
231 wxPostEvent((*EntryIter), DeselectEntryEvent);