1 // XCCalendarDayEntry.cpp - Xestia Calendar XCCalendarDayEntry 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 "XCCalendarDayEntry.h"
21 BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel)
22 EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent)
23 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
24 EVT_LEFT_DOWN(XCCalendarDayEntry::LeftClick)
29 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
30 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
32 DayPanel = parent->GetParent();
35 this->SetMinSize(wxSize(65, 30));
37 EventTextData = title.mb_str();
38 EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
39 EventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
41 wxFont eventTimeFont = EventTime->GetFont();
42 eventTimeFont.MakeBold();
43 EventTime->SetFont(eventTimeFont);
45 wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
46 wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
48 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
49 AlarmIconBitmap = wxBitmap(icons_alert_png, -1);
51 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
52 PriorityIconBitmap = wxBitmap(icons_priority_png, -1);
54 AlarmIcon->SetBitmap(AlarmIconBitmap);
55 HighPriorityIcon->SetBitmap(PriorityIconBitmap);
57 Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
58 AlarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
59 HighPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
60 EventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61 EventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62 DayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
68 XCCalendarDayEntry::~XCCalendarDayEntry(){
70 // Destory the controls from the widget.
74 void XCCalendarDayEntry::Repaint(){
78 // Get the wxSizerItem for the top date and the entries part.
80 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
84 Test.SetX(this->GetClientRect().GetX());
85 Test.SetY(this->GetClientRect().GetY());
86 Test.SetHeight(this->GetClientRect().GetHeight());
87 Test.SetWidth(this->GetClientRect().GetWidth());
89 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
91 dc.DrawRectangle(this->GetClientRect());
93 // Draw the calendar colour.
95 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
96 dc.SetBrush(wxBrush(wxColor(EntryColour.red,
98 EntryColour.blue), wxBRUSHSTYLE_SOLID));
99 dc.DrawRectangle(wxRect(1,1,10,28));
103 void XCCalendarDayEntry::UpdateInformation(){
107 // Check if the high priority icon needs to be displayed.
109 if (HasHighPriority == true){
111 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
113 HighPriorityIcon->Show(true);
119 HighPriorityIcon->Show(false);
123 // Check if the alarm icon needs to be displayed.
125 if (HasAlarm == true){
127 switch(PositionMode){
129 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
132 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
136 AlarmIcon->Show(true);
142 AlarmIcon->Show(false);
148 switch(PositionMode){
150 EventText->SetPosition(wxPoint(FirstPosition,14));
151 EventTime->SetPosition(wxPoint(FirstPosition,3));
154 EventText->SetPosition(wxPoint(SecondPosition,14));
155 EventTime->SetPosition(wxPoint(FirstPosition,3));
158 EventText->SetPosition(wxPoint(ThirdPosition,14));
159 EventTime->SetPosition(wxPoint(FirstPosition,3));
165 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
171 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
173 // Adjust the Event text so it is displayed properly.
175 switch(PositionMode){
177 EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
178 EventTime->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
181 EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
182 EventTime->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
185 EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),14));
186 EventTime->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
190 // Refresh the window.
196 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
198 // Change the background of the widget to mark
199 // the entry as selected.
201 this->SetBackgroundColour(wxColor(255,215,0));
202 wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
203 DeselectOthersEvent.SetInt(entryID);
204 DeselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
205 wxPostEvent(DayPanel, DeselectOthersEvent);
209 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
211 this->SetBackgroundColour(wxNullColour);
215 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
217 this->timeHour = timeHour;
218 this->timeMinute = timeMinute;
219 this->timeSecond = timeSecond;
221 string timeOutput = BuildEventTime(timeHour, timeMinute);
222 EventTime->SetLabel(timeOutput);
226 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
228 EntryColour = *ColourIn;
233 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
235 HasAlarm = DisplayValue;
240 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
242 HasHighPriority = DisplayValue;
247 bool XCCalendarDayEntry::GetDisplayAlarm(){
253 bool XCCalendarDayEntry::GetDisplayHighPriority(){
255 return HasHighPriority;
259 int XCCalendarDayEntry::GetID(){
265 int XCCalendarDayEntry::GetCalendarID(){
271 int XCCalendarDayEntry::GetAccountID(){
277 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
283 timeOutput += to_string(timeHour - 12);
285 } else if (timeHour > 0){
287 timeOutput += to_string(timeHour);
289 } else if (timeHour == 0){
291 timeOutput += to_string(12);
297 if (timeMinute < 10){
301 timeOutput += to_string(timeMinute);
313 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int entryID){
315 this->accountID = accountID;
316 this->calendarID = calendarID;
317 this->entryID = entryID;
321 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
323 this->afterSpacer = afterSpacer;
327 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
333 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
335 showAccount = statusInput;
339 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
341 showCalendar = statusInput;
345 bool XCCalendarDayEntry::GetShowAccountStatus(){
351 bool XCCalendarDayEntry::GetShowCalendarStatus(){