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 BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel)
22 EVT_PAINT(XCCalendarDayEntry::PaintFrameEvent)
23 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
24 EVT_LEFT_UP(XCCalendarDayEntry::LeftClick)
25 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
30 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
31 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
33 dayPanel = parent->GetParent();
36 this->SetMinSize(wxSize(65, 30));
38 eventTextData = title.mb_str();
39 eventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
40 eventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
42 wxFont eventTimeFont = eventTime->GetFont();
43 eventTimeFont.MakeBold();
44 eventTime->SetFont(eventTimeFont);
46 wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
47 wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
49 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
50 alarmIconBitmap = wxBitmap(icons_alert_png, -1);
52 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
53 priorityIconBitmap = wxBitmap(icons_priority_png, -1);
55 alarmIcon->SetBitmap(alarmIconBitmap);
56 highPriorityIcon->SetBitmap(priorityIconBitmap);
58 Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
60 alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61 highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62 eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
63 eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
64 dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
66 alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
67 highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
68 eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
69 eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
70 dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
76 XCCalendarDayEntry::~XCCalendarDayEntry(){
78 // Destory the controls from the widget.
82 void XCCalendarDayEntry::Repaint(){
86 // Get the wxSizerItem for the top date and the entries part.
88 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
92 Test.SetX(this->GetClientRect().GetX());
93 Test.SetY(this->GetClientRect().GetY());
94 Test.SetHeight(this->GetClientRect().GetHeight());
95 Test.SetWidth(this->GetClientRect().GetWidth());
97 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
99 dc.DrawRectangle(this->GetClientRect());
101 // Draw the calendar colour.
103 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
104 dc.SetBrush(wxBrush(wxColor(entryColour.red,
106 entryColour.blue), wxBRUSHSTYLE_SOLID));
107 dc.DrawRectangle(wxRect(1,1,10,28));
111 void XCCalendarDayEntry::UpdateInformation(){
115 // Check if the high priority icon needs to be displayed.
117 if (hasHighPriority == true){
119 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
121 highPriorityIcon->Show(true);
127 highPriorityIcon->Show(false);
131 // Check if the alarm icon needs to be displayed.
133 if (hasAlarm == true){
135 switch(positionMode){
137 alarmIcon->SetPosition(wxPoint(firstPosition,7));
140 alarmIcon->SetPosition(wxPoint(secondPosition,7));
144 alarmIcon->Show(true);
150 alarmIcon->Show(false);
156 switch(positionMode){
158 eventText->SetPosition(wxPoint(firstPosition,14));
159 eventTime->SetPosition(wxPoint(firstPosition,3));
162 eventText->SetPosition(wxPoint(secondPosition,14));
163 eventTime->SetPosition(wxPoint(firstPosition,3));
166 eventText->SetPosition(wxPoint(thirdPosition,14));
167 eventTime->SetPosition(wxPoint(firstPosition,3));
173 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &paintEvent){
179 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
181 // Adjust the Event text so it is displayed properly.
183 switch(positionMode){
185 eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
186 eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
189 eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
190 eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
193 eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
194 eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
198 // Refresh the window.
204 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
206 // Change the background of the widget to mark
207 // the entry as selected.
209 this->SetBackgroundColour(wxColor(255,215,0));
210 wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
211 deselectOthersEvent.SetInt(eventID);
212 deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
213 wxPostEvent(dayPanel, deselectOthersEvent);
217 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
219 // Sent an event to the month view control.
221 EventProperties *eventData = new EventProperties;
222 eventData->calendarID = calendarID;
223 eventData->eventID = eventID;
225 wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
226 eventMenu.SetClientData(eventData);
227 eventMenu.SetId(ID_DISPLAYEVENTMENU);
228 wxPostEvent(this->GetParent()->GetParent(), eventMenu);
232 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
234 this->SetBackgroundColour(wxNullColour);
238 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
240 this->timeHour = timeHour;
241 this->timeMinute = timeMinute;
242 this->timeSecond = timeSecond;
244 string timeOutput = BuildEventTime(timeHour, timeMinute);
245 eventTime->SetLabel(timeOutput);
249 void XCCalendarDayEntry::SetColour(Colour *colourIn){
251 entryColour = *colourIn;
256 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
258 hasAlarm = displayValue;
263 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
265 hasHighPriority = displayValue;
270 bool XCCalendarDayEntry::GetDisplayAlarm(){
276 bool XCCalendarDayEntry::GetDisplayHighPriority(){
278 return hasHighPriority;
282 int XCCalendarDayEntry::GetID(){
288 int XCCalendarDayEntry::GetCalendarID(){
294 int XCCalendarDayEntry::GetEventID(){
300 int XCCalendarDayEntry::GetAccountID(){
306 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
312 timeOutput += to_string(timeHour - 12);
314 } else if (timeHour > 0){
316 timeOutput += to_string(timeHour);
318 } else if (timeHour == 0){
320 timeOutput += to_string(12);
326 if (timeMinute < 10){
330 timeOutput += to_string(timeMinute);
342 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
344 this->accountID = accountID;
345 this->calendarID = calendarID;
346 this->eventID = eventID;
350 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
352 this->afterSpacer = afterSpacer;
356 void XCCalendarDayEntry::SetEventName(string eventName){
358 eventText->SetLabel((wxString)eventName);
362 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
368 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
370 showAccount = statusInput;
374 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
376 showCalendar = statusInput;
380 bool XCCalendarDayEntry::GetShowAccountStatus(){
386 bool XCCalendarDayEntry::GetShowCalendarStatus(){