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.
104 // Disconnect and unbind.
106 calendarColour->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
107 alarmIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
108 highPriorityIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
109 eventText->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
110 eventTime->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
111 dayPanel->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
113 calendarColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
114 alarmIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
115 highPriorityIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
116 eventText->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
117 eventTime->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
118 dayPanel->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
120 Unbind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
122 // Delete the controls.
132 delete calendarColour;
133 calendarColour = nullptr;
138 delete highPriorityIcon;
141 this->SetSizer(nullptr, true);
145 void XCCalendarDayEntry::UpdateInformation(){
149 // Check if the high priority icon needs to be displayed.
151 if (hasHighPriority == true){
153 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
155 highPriorityIcon->Show(true);
161 highPriorityIcon->Show(false);
165 // Check if the alarm icon needs to be displayed.
167 if (hasAlarm == true){
169 switch(positionMode){
171 alarmIcon->SetPosition(wxPoint(firstPosition,7));
174 alarmIcon->SetPosition(wxPoint(secondPosition,7));
178 alarmIcon->Show(true);
184 alarmIcon->Show(false);
190 switch(positionMode){
192 eventText->SetPosition(wxPoint(firstPosition,14));
193 eventTime->SetPosition(wxPoint(firstPosition,3));
196 eventText->SetPosition(wxPoint(secondPosition,14));
197 eventTime->SetPosition(wxPoint(firstPosition,3));
200 eventText->SetPosition(wxPoint(thirdPosition,14));
201 eventTime->SetPosition(wxPoint(firstPosition,3));
207 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
209 // Adjust the Event text so it is displayed properly.
211 switch(positionMode){
213 eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
214 eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
217 eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
218 eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
221 eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
222 eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
226 // Resize the main panel.
228 mainPanel->SetSize(this->GetSize());
230 // Refresh the window.
236 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
238 // Change the background of the widget to mark
239 // the entry as selected.
241 mainPanel->SetBackgroundColour(wxColor(255,215,0));
242 wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
243 deselectOthersEvent.SetInt(eventID);
244 deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
245 wxPostEvent(dayPanel, deselectOthersEvent);
250 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
252 // Sent an event to the month view control.
254 EventProperties *eventData = new EventProperties;
255 eventData->calendarID = calendarID;
256 eventData->eventID = eventID;
258 wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
259 eventMenu.SetClientData(eventData);
260 eventMenu.SetId(ID_DISPLAYEVENTMENU);
261 wxPostEvent(this->GetParent()->GetParent(), eventMenu);
265 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
267 mainPanel->SetBackgroundColour(wxNullColour);
272 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
274 this->timeHour = timeHour;
275 this->timeMinute = timeMinute;
276 this->timeSecond = timeSecond;
278 string timeOutput = BuildEventTime(timeHour, timeMinute);
279 eventTime->SetLabel(timeOutput);
283 void XCCalendarDayEntry::SetColour(Colour *colourIn){
285 calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha));
290 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
292 hasAlarm = displayValue;
297 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
299 hasHighPriority = displayValue;
304 bool XCCalendarDayEntry::GetDisplayAlarm(){
310 bool XCCalendarDayEntry::GetDisplayHighPriority(){
312 return hasHighPriority;
316 int XCCalendarDayEntry::GetID(){
322 int XCCalendarDayEntry::GetCalendarID(){
328 int XCCalendarDayEntry::GetEventID(){
334 int XCCalendarDayEntry::GetAccountID(){
340 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
346 timeOutput += to_string(timeHour - 12);
348 } else if (timeHour > 0){
350 timeOutput += to_string(timeHour);
352 } else if (timeHour == 0){
354 timeOutput += to_string(12);
360 if (timeMinute < 10){
364 timeOutput += to_string(timeMinute);
376 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
378 this->accountID = accountID;
379 this->calendarID = calendarID;
380 this->eventID = eventID;
384 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
386 this->afterSpacer = afterSpacer;
390 void XCCalendarDayEntry::SetEventName(string eventName){
392 eventText->SetLabel(wxString(eventName));
396 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
402 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
404 showAccount = statusInput;
408 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
410 showCalendar = statusInput;
414 bool XCCalendarDayEntry::GetShowAccountStatus(){
420 bool XCCalendarDayEntry::GetShowCalendarStatus(){