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(){