// XCCalendarDayEntry.cpp - Xestia Calendar XCCalendarDayEntry widget class. // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "XCCalendarDayEntry.h" BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel) EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent) EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent) EVT_LEFT_DOWN(XCCalendarDayEntry::LeftClick) END_EVENT_TABLE() using namespace std; XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id) : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){ DayPanel = parent->GetParent(); entryID = id; this->SetMinSize(wxSize(65, 30)); EventTextData = title.mb_str(); EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END); EventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0); wxFont eventTimeFont = EventTime->GetFont(); eventTimeFont.MakeBold(); EventTime->SetFont(eventTimeFont); wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png)); wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png)); wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG); AlarmIconBitmap = wxBitmap(icons_alert_png, -1); wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG); PriorityIconBitmap = wxBitmap(icons_priority_png, -1); AlarmIcon->SetBitmap(AlarmIconBitmap); HighPriorityIcon->SetBitmap(PriorityIconBitmap); Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect)); AlarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); HighPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); EventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); EventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); DayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); UpdateInformation(); } XCCalendarDayEntry::~XCCalendarDayEntry(){ // Destory the controls from the widget. } void XCCalendarDayEntry::Repaint(){ wxPaintDC dc(this); // Get the wxSizerItem for the top date and the entries part. dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT)); /*wxRect Test; Test.SetX(this->GetClientRect().GetX()); Test.SetY(this->GetClientRect().GetY()); Test.SetHeight(this->GetClientRect().GetHeight()); Test.SetWidth(this->GetClientRect().GetWidth()); cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/ dc.DrawRectangle(this->GetClientRect()); // Draw the calendar colour. dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT)); dc.SetBrush(wxBrush(wxColor(EntryColour.red, EntryColour.green, EntryColour.blue), wxBRUSHSTYLE_SOLID)); dc.DrawRectangle(wxRect(1,1,10,28)); } void XCCalendarDayEntry::UpdateInformation(){ PositionMode = 0; // Check if the high priority icon needs to be displayed. if (HasHighPriority == true){ HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7)); HighPriorityIcon->Show(true); PositionMode++; } else { HighPriorityIcon->Show(false); } // Check if the alarm icon needs to be displayed. if (HasAlarm == true){ switch(PositionMode){ case 0: AlarmIcon->SetPosition(wxPoint(FirstPosition,7)); break; case 1: AlarmIcon->SetPosition(wxPoint(SecondPosition,7)); break; } AlarmIcon->Show(true); PositionMode++; } else { AlarmIcon->Show(false); } // Now set the text. switch(PositionMode){ case 0: EventText->SetPosition(wxPoint(FirstPosition,14)); EventTime->SetPosition(wxPoint(FirstPosition,3)); break; case 1: EventText->SetPosition(wxPoint(SecondPosition,14)); EventTime->SetPosition(wxPoint(FirstPosition,3)); break; case 2: EventText->SetPosition(wxPoint(ThirdPosition,14)); EventTime->SetPosition(wxPoint(FirstPosition,3)); break; } } void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){ Repaint(); } void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){ // Adjust the Event text so it is displayed properly. switch(PositionMode){ case 0: EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15)); EventTime->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15)); break; case 1: EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); EventTime->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); break; case 2: EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),14)); EventTime->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15)); break; } // Refresh the window. this->Refresh(); } void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){ // Change the background of the widget to mark // the entry as selected. this->SetBackgroundColour(wxColor(255,215,0)); wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); DeselectOthersEvent.SetInt(entryID); DeselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES); wxPostEvent(DayPanel, DeselectOthersEvent); } void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ this->SetBackgroundColour(wxNullColour); } void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){ this->timeHour = timeHour; this->timeMinute = timeMinute; this->timeSecond = timeSecond; string timeOutput = BuildEventTime(timeHour, timeMinute); EventTime->SetLabel(timeOutput); } void XCCalendarDayEntry::SetColour(Colour *ColourIn){ EntryColour = *ColourIn; Repaint(); } void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){ HasAlarm = DisplayValue; UpdateInformation(); } void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){ HasHighPriority = DisplayValue; UpdateInformation(); } bool XCCalendarDayEntry::GetDisplayAlarm(){ return HasAlarm; } bool XCCalendarDayEntry::GetDisplayHighPriority(){ return HasHighPriority; } int XCCalendarDayEntry::GetID(){ return entryID; } int XCCalendarDayEntry::GetCalendarID(){ return calendarID; } int XCCalendarDayEntry::GetAccountID(){ return accountID; } string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){ string timeOutput; if (timeHour > 12){ timeOutput += to_string(timeHour - 12); } else if (timeHour > 0){ timeOutput += to_string(timeHour); } else if (timeHour == 0){ timeOutput += to_string(12); } timeOutput += ":"; if (timeMinute < 10){ timeOutput += "0"; } timeOutput += to_string(timeMinute); if (timeHour < 12){ timeOutput += "am"; } else { timeOutput += "pm"; } return timeOutput; } void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int entryID){ this->accountID = accountID; this->calendarID = calendarID; this->entryID = entryID; } void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){ this->afterSpacer = afterSpacer; } wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){ return afterSpacer; } bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){ showAccount = statusInput; } bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){ showCalendar = statusInput; } bool XCCalendarDayEntry::GetShowAccountStatus(){ return showAccount; } bool XCCalendarDayEntry::GetShowCalendarStatus(){ return showCalendar; }