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_PAINT(XCCalendarDayEntry::PaintFrameEvent)
25 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
26 EVT_LEFT_UP(XCCalendarDayEntry::LeftClick)
27 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
32 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
33 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
34 dayPanel = parent->GetParent();
37 this->SetMinSize(wxSize(65, 30));
39 eventTextData = title.mb_str();
40 eventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
41 eventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
43 wxFont eventTimeFont = eventTime->GetFont();
44 eventTimeFont.MakeBold();
45 eventTime->SetFont(eventTimeFont);
47 wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
48 wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
50 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
51 alarmIconBitmap = wxBitmap(icons_alert_png, -1);
53 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
54 priorityIconBitmap = wxBitmap(icons_priority_png, -1);
56 alarmIcon->SetBitmap(alarmIconBitmap);
57 highPriorityIcon->SetBitmap(priorityIconBitmap);
59 alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
60 highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61 eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62 eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
63 dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
65 alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
66 highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
67 eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
68 eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
69 dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
73 // Bind events to the control.
75 Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
78 XCCalendarDayEntry::~XCCalendarDayEntry(){
80 // Destory the controls from the widget.
84 void XCCalendarDayEntry::Repaint(){
88 // Get the wxSizerItem for the top date and the entries part.
90 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
94 Test.SetX(this->GetClientRect().GetX());
95 Test.SetY(this->GetClientRect().GetY());
96 Test.SetHeight(this->GetClientRect().GetHeight());
97 Test.SetWidth(this->GetClientRect().GetWidth());
99 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
101 dc.DrawRectangle(this->GetClientRect());
103 // Draw the calendar colour.
105 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
106 dc.SetBrush(wxBrush(wxColor(entryColour.red,
108 entryColour.blue), wxBRUSHSTYLE_SOLID));
109 dc.DrawRectangle(wxRect(1,1,10,28));
113 void XCCalendarDayEntry::UpdateInformation(){
117 // Check if the high priority icon needs to be displayed.
119 if (hasHighPriority == true){
121 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
123 highPriorityIcon->Show(true);
129 highPriorityIcon->Show(false);
133 // Check if the alarm icon needs to be displayed.
135 if (hasAlarm == true){
137 switch(positionMode){
139 alarmIcon->SetPosition(wxPoint(firstPosition,7));
142 alarmIcon->SetPosition(wxPoint(secondPosition,7));
146 alarmIcon->Show(true);
152 alarmIcon->Show(false);
158 switch(positionMode){
160 eventText->SetPosition(wxPoint(firstPosition,14));
161 eventTime->SetPosition(wxPoint(firstPosition,3));
164 eventText->SetPosition(wxPoint(secondPosition,14));
165 eventTime->SetPosition(wxPoint(firstPosition,3));
168 eventText->SetPosition(wxPoint(thirdPosition,14));
169 eventTime->SetPosition(wxPoint(firstPosition,3));
175 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &paintEvent){
181 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
183 // Adjust the Event text so it is displayed properly.
185 switch(positionMode){
187 eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
188 eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
191 eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
192 eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
195 eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
196 eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
200 // Refresh the window.
206 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
208 // Change the background of the widget to mark
209 // the entry as selected.
211 this->SetBackgroundColour(wxColor(255,215,0));
212 wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
213 deselectOthersEvent.SetInt(eventID);
214 deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
215 wxPostEvent(dayPanel, deselectOthersEvent);
219 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
221 // Sent an event to the month view control.
223 EventProperties *eventData = new EventProperties;
224 eventData->calendarID = calendarID;
225 eventData->eventID = eventID;
227 wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
228 eventMenu.SetClientData(eventData);
229 eventMenu.SetId(ID_DISPLAYEVENTMENU);
230 wxPostEvent(this->GetParent()->GetParent(), eventMenu);
234 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
236 this->SetBackgroundColour(wxNullColour);
240 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
242 this->timeHour = timeHour;
243 this->timeMinute = timeMinute;
244 this->timeSecond = timeSecond;
246 string timeOutput = BuildEventTime(timeHour, timeMinute);
247 eventTime->SetLabel(timeOutput);
251 void XCCalendarDayEntry::SetColour(Colour *colourIn){
253 entryColour = *colourIn;
258 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
260 hasAlarm = displayValue;
265 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
267 hasHighPriority = displayValue;
272 bool XCCalendarDayEntry::GetDisplayAlarm(){
278 bool XCCalendarDayEntry::GetDisplayHighPriority(){
280 return hasHighPriority;
284 int XCCalendarDayEntry::GetID(){
290 int XCCalendarDayEntry::GetCalendarID(){
296 int XCCalendarDayEntry::GetEventID(){
302 int XCCalendarDayEntry::GetAccountID(){
308 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
314 timeOutput += to_string(timeHour - 12);
316 } else if (timeHour > 0){
318 timeOutput += to_string(timeHour);
320 } else if (timeHour == 0){
322 timeOutput += to_string(12);
328 if (timeMinute < 10){
332 timeOutput += to_string(timeMinute);
344 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
346 this->accountID = accountID;
347 this->calendarID = calendarID;
348 this->eventID = eventID;
352 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
354 this->afterSpacer = afterSpacer;
358 void XCCalendarDayEntry::SetEventName(string eventName){
360 eventText->SetLabel((wxString)eventName);
364 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
370 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
372 showAccount = statusInput;
376 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
378 showCalendar = statusInput;
382 bool XCCalendarDayEntry::GetShowAccountStatus(){
388 bool XCCalendarDayEntry::GetShowCalendarStatus(){