// 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) { Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect)); DayPanel = parent->GetParent(); EntryID = id; this->SetMinSize(wxSize(65, 30)); EventTextData = title.mb_str(); EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END); AlarmIconBitmap.LoadFile("AlertIcon.png", wxBITMAP_DEFAULT_TYPE); PriorityIconBitmap.LoadFile("PriorityIcon.png", wxBITMAP_DEFAULT_TYPE); AlarmIcon->SetBitmap(AlarmIconBitmap); HighPriorityIcon->SetBitmap(PriorityIconBitmap); 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,8)); break; case 1: EventText->SetPosition(wxPoint(SecondPosition,8)); break; case 2: EventText->SetPosition(wxPoint(ThirdPosition,8)); 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)); break; case 1: EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15)); break; case 2: EventText->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); wxPostEvent(DayPanel, DeselectOthersEvent); } void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ this->SetBackgroundColour(wxNullColour); } void XCCalendarDayEntry::SetColour(Colour *ColourIn){ EntryColour = *ColourIn; } 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; }