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_DOWN(XCCalendarDayEntry::LeftClick)
29 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
30 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
32 DayPanel = parent->GetParent();
35 this->SetMinSize(wxSize(65, 30));
37 EventTextData = title.mb_str();
38 EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END);
40 wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
41 wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
43 wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
44 AlarmIconBitmap = wxBitmap(icons_alert_png, -1);
46 wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
47 PriorityIconBitmap = wxBitmap(icons_priority_png, -1);
49 AlarmIcon->SetBitmap(AlarmIconBitmap);
50 HighPriorityIcon->SetBitmap(PriorityIconBitmap);
52 Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
53 AlarmIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
54 HighPriorityIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
55 EventText->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61 XCCalendarDayEntry::~XCCalendarDayEntry(){
63 // Destory the controls from the widget.
67 void XCCalendarDayEntry::Repaint(){
71 // Get the wxSizerItem for the top date and the entries part.
73 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
77 Test.SetX(this->GetClientRect().GetX());
78 Test.SetY(this->GetClientRect().GetY());
79 Test.SetHeight(this->GetClientRect().GetHeight());
80 Test.SetWidth(this->GetClientRect().GetWidth());
82 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
84 dc.DrawRectangle(this->GetClientRect());
86 // Draw the calendar colour.
88 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
89 dc.SetBrush(wxBrush(wxColor(EntryColour.red,
91 EntryColour.blue), wxBRUSHSTYLE_SOLID));
92 dc.DrawRectangle(wxRect(1,1,10,28));
96 void XCCalendarDayEntry::UpdateInformation(){
100 // Check if the high priority icon needs to be displayed.
102 if (HasHighPriority == true){
104 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
106 HighPriorityIcon->Show(true);
112 HighPriorityIcon->Show(false);
116 // Check if the alarm icon needs to be displayed.
118 if (HasAlarm == true){
120 switch(PositionMode){
122 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
125 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
129 AlarmIcon->Show(true);
135 AlarmIcon->Show(false);
141 switch(PositionMode){
143 EventText->SetPosition(wxPoint(FirstPosition,8));
146 EventText->SetPosition(wxPoint(SecondPosition,8));
149 EventText->SetPosition(wxPoint(ThirdPosition,8));
155 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
161 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
163 // Adjust the Event text so it is displayed properly.
165 switch(PositionMode){
167 EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
170 EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
173 EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
177 // Refresh the window.
183 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
185 // Change the background of the widget to mark
186 // the entry as selected.
188 this->SetBackgroundColour(wxColor(255,215,0));
189 wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
190 DeselectOthersEvent.SetInt(EntryID);
191 wxPostEvent(DayPanel, DeselectOthersEvent);
195 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
197 this->SetBackgroundColour(wxNullColour);
201 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
203 EntryColour = *ColourIn;
207 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
209 HasAlarm = DisplayValue;
214 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
216 HasHighPriority = DisplayValue;
221 bool XCCalendarDayEntry::GetDisplayAlarm(){
227 bool XCCalendarDayEntry::GetDisplayHighPriority(){
229 return HasHighPriority;
233 int XCCalendarDayEntry::GetID(){