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 wxDEFINE_EVENT(XCCALENDARDAYENTRY_DESELECT, wxCommandEvent);
23 BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel)
24 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
25 EVT_LEFT_UP(XCCalendarDayEntry::LeftClick)
26 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
31 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
32 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
33 dayPanel = parent->GetParent();
36 this->SetMinSize(wxSize(65, 30));
38 // Setup the main panel and main sizer.
40 mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), this->GetSize(), wxTAB_TRAVERSAL|wxSIMPLE_BORDER);
41 mainSizer = new wxBoxSizer( wxVERTICAL );
43 // Setup the calendar colour.
45 calendarColour = new wxPanel(mainPanel, wxID_ANY, wxPoint(0,0), wxSize(10, 30), wxTAB_TRAVERSAL|wxEXPAND, "Calendar Colour");
46 calendarColour->SetBackgroundColour(wxColour(80, 40, 40, 100));
48 // Setup the event text.
50 eventTextData = title.mb_str();
51 eventText = new wxStaticText(mainPanel, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
52 eventTime = new wxStaticText(mainPanel, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
54 wxFont eventTimeFont = eventTime->GetFont();
55 eventTimeFont.MakeBold();
56 eventTime->SetFont(eventTimeFont);
60 wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
61 wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
63 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
64 alarmIconBitmap = wxBitmap(icons_alert_png, -1);
66 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
67 priorityIconBitmap = wxBitmap(icons_priority_png, -1);
69 alarmIcon->SetBitmap(alarmIconBitmap);
70 highPriorityIcon->SetBitmap(priorityIconBitmap);
72 // Setup the connections for the control.
74 calendarColour->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
75 alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
76 highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
77 eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
78 eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
79 dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
81 calendarColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
82 alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
83 highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
84 eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
85 eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
86 dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
90 // Bind events to the control.
92 Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
94 // Set the control's sizer.
96 this->SetSizer(mainSizer);
97 mainSizer->Add(mainPanel, 0, wxEXPAND, 1);
100 XCCalendarDayEntry::~XCCalendarDayEntry(){
102 // Destory the controls from the widget.
106 void XCCalendarDayEntry::UpdateInformation(){
110 // Check if the high priority icon needs to be displayed.
112 if (hasHighPriority == true){
114 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
116 highPriorityIcon->Show(true);
122 highPriorityIcon->Show(false);
126 // Check if the alarm icon needs to be displayed.
128 if (hasAlarm == true){
130 switch(positionMode){
132 alarmIcon->SetPosition(wxPoint(firstPosition,7));
135 alarmIcon->SetPosition(wxPoint(secondPosition,7));
139 alarmIcon->Show(true);
145 alarmIcon->Show(false);
151 switch(positionMode){
153 eventText->SetPosition(wxPoint(firstPosition,14));
154 eventTime->SetPosition(wxPoint(firstPosition,3));
157 eventText->SetPosition(wxPoint(secondPosition,14));
158 eventTime->SetPosition(wxPoint(firstPosition,3));
161 eventText->SetPosition(wxPoint(thirdPosition,14));
162 eventTime->SetPosition(wxPoint(firstPosition,3));
168 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
170 // Adjust the Event text so it is displayed properly.
172 switch(positionMode){
174 eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
175 eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
178 eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
179 eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
182 eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
183 eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
187 // Resize the main panel.
189 mainPanel->SetSize(this->GetSize());
191 // Refresh the window.
197 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
199 // Change the background of the widget to mark
200 // the entry as selected.
202 mainPanel->SetBackgroundColour(wxColor(255,215,0));
203 wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
204 deselectOthersEvent.SetInt(eventID);
205 deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
206 wxPostEvent(dayPanel, deselectOthersEvent);
211 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
213 // Sent an event to the month view control.
215 EventProperties *eventData = new EventProperties;
216 eventData->calendarID = calendarID;
217 eventData->eventID = eventID;
219 wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
220 eventMenu.SetClientData(eventData);
221 eventMenu.SetId(ID_DISPLAYEVENTMENU);
222 wxPostEvent(this->GetParent()->GetParent(), eventMenu);
226 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
228 mainPanel->SetBackgroundColour(wxNullColour);
233 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
235 this->timeHour = timeHour;
236 this->timeMinute = timeMinute;
237 this->timeSecond = timeSecond;
239 string timeOutput = BuildEventTime(timeHour, timeMinute);
240 eventTime->SetLabel(timeOutput);
244 void XCCalendarDayEntry::SetColour(Colour *colourIn){
246 calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha));
251 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
253 hasAlarm = displayValue;
258 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
260 hasHighPriority = displayValue;
265 bool XCCalendarDayEntry::GetDisplayAlarm(){
271 bool XCCalendarDayEntry::GetDisplayHighPriority(){
273 return hasHighPriority;
277 int XCCalendarDayEntry::GetID(){
283 int XCCalendarDayEntry::GetCalendarID(){
289 int XCCalendarDayEntry::GetEventID(){
295 int XCCalendarDayEntry::GetAccountID(){
301 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
307 timeOutput += to_string(timeHour - 12);
309 } else if (timeHour > 0){
311 timeOutput += to_string(timeHour);
313 } else if (timeHour == 0){
315 timeOutput += to_string(12);
321 if (timeMinute < 10){
325 timeOutput += to_string(timeMinute);
337 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
339 this->accountID = accountID;
340 this->calendarID = calendarID;
341 this->eventID = eventID;
345 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
347 this->afterSpacer = afterSpacer;
351 void XCCalendarDayEntry::SetEventName(string eventName){
353 eventText->SetLabel((wxString)eventName);
357 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
363 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
365 showAccount = statusInput;
369 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
371 showCalendar = statusInput;
375 bool XCCalendarDayEntry::GetShowAccountStatus(){
381 bool XCCalendarDayEntry::GetShowCalendarStatus(){