// 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" wxDEFINE_EVENT(XCCALENDARDAYENTRY_DESELECT, wxCommandEvent); BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel) EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent) EVT_LEFT_UP(XCCalendarDayEntry::LeftClick) EVT_RIGHT_UP(XCCalendarDayEntry::RightClick) 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(); eventID = id; this->SetMinSize(wxSize(65, 30)); // Setup the main panel and main sizer. mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), this->GetSize(), wxTAB_TRAVERSAL|wxSIMPLE_BORDER); mainSizer = new wxBoxSizer( wxVERTICAL ); // Setup the calendar colour. calendarColour = new wxPanel(mainPanel, wxID_ANY, wxPoint(0,0), wxSize(10, 30), wxTAB_TRAVERSAL|wxEXPAND, "Calendar Colour"); calendarColour->SetBackgroundColour(wxColour(80, 40, 40, 100)); // Setup the event text. eventTextData = title.mb_str(); eventText = new wxStaticText(mainPanel, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END); eventTime = new wxStaticText(mainPanel, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0); wxFont eventTimeFont = eventTime->GetFont(); eventTimeFont.MakeBold(); eventTime->SetFont(eventTimeFont); // Setup the images. 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); // Setup the connections for the control. calendarColour->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); 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); calendarColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); UpdateInformation(); // Bind events to the control. Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT); // Set the control's sizer. this->SetSizer(mainSizer); mainSizer->Add(mainPanel, 0, wxEXPAND, 1); } XCCalendarDayEntry::~XCCalendarDayEntry(){ // Destory the controls from the widget. // Disconnect and unbind. calendarColour->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); alarmIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); highPriorityIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); eventText->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); eventTime->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); dayPanel->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); calendarColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); alarmIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); highPriorityIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); eventText->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); eventTime->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); dayPanel->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); Unbind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT); // Delete the controls. mainSizer->Clear(); delete eventText; eventText = nullptr; delete eventTime; eventTime = nullptr; delete calendarColour; calendarColour = nullptr; delete mainPanel; mainPanel = nullptr; delete highPriorityIcon; delete alarmIcon; this->SetSizer(nullptr, true); } 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::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; } // Resize the main panel. mainPanel->SetSize(this->GetSize()); // Refresh the window. this->Refresh(); } void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){ // Change the background of the widget to mark // the entry as selected. mainPanel->SetBackgroundColour(wxColor(255,215,0)); wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES); deselectOthersEvent.SetInt(eventID); deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES); wxPostEvent(dayPanel, deselectOthersEvent); this->Refresh(); } void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){ // Sent an event to the month view control. EventProperties *eventData = new EventProperties; eventData->calendarID = calendarID; eventData->eventID = eventID; wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU); eventMenu.SetClientData(eventData); eventMenu.SetId(ID_DISPLAYEVENTMENU); wxPostEvent(this->GetParent()->GetParent(), eventMenu); } void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){ mainPanel->SetBackgroundColour(wxNullColour); this->Refresh(); } 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){ calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha)); this->Refresh(); } 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 eventID; } int XCCalendarDayEntry::GetCalendarID(){ return calendarID; } int XCCalendarDayEntry::GetEventID(){ return eventID; } 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 eventID){ this->accountID = accountID; this->calendarID = calendarID; this->eventID = eventID; } void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){ this->afterSpacer = afterSpacer; } void XCCalendarDayEntry::SetEventName(string eventName){ eventText->SetLabel(wxString(eventName)); } wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){ return afterSpacer; } void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){ showAccount = statusInput; } void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){ showCalendar = statusInput; } bool XCCalendarDayEntry::GetShowAccountStatus(){ return showAccount; } bool XCCalendarDayEntry::GetShowCalendarStatus(){ return showCalendar; }