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 AlarmIconBitmap.LoadFile("AlertIcon.png", wxBITMAP_DEFAULT_TYPE);
41 PriorityIconBitmap.LoadFile("PriorityIcon.png", wxBITMAP_DEFAULT_TYPE);
43 AlarmIcon->SetBitmap(AlarmIconBitmap);
44 HighPriorityIcon->SetBitmap(PriorityIconBitmap);
46 Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
47 AlarmIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
48 HighPriorityIcon->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
49 EventText->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
55 XCCalendarDayEntry::~XCCalendarDayEntry(){
57 // Destory the controls from the widget.
61 void XCCalendarDayEntry::Repaint(){
65 // Get the wxSizerItem for the top date and the entries part.
67 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
71 Test.SetX(this->GetClientRect().GetX());
72 Test.SetY(this->GetClientRect().GetY());
73 Test.SetHeight(this->GetClientRect().GetHeight());
74 Test.SetWidth(this->GetClientRect().GetWidth());
76 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
78 dc.DrawRectangle(this->GetClientRect());
80 // Draw the calendar colour.
82 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
83 dc.SetBrush(wxBrush(wxColor(EntryColour.red,
85 EntryColour.blue), wxBRUSHSTYLE_SOLID));
86 dc.DrawRectangle(wxRect(1,1,10,28));
90 void XCCalendarDayEntry::UpdateInformation(){
94 // Check if the high priority icon needs to be displayed.
96 if (HasHighPriority == true){
98 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
100 HighPriorityIcon->Show(true);
106 HighPriorityIcon->Show(false);
110 // Check if the alarm icon needs to be displayed.
112 if (HasAlarm == true){
114 switch(PositionMode){
116 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
119 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
123 AlarmIcon->Show(true);
129 AlarmIcon->Show(false);
135 switch(PositionMode){
137 EventText->SetPosition(wxPoint(FirstPosition,8));
140 EventText->SetPosition(wxPoint(SecondPosition,8));
143 EventText->SetPosition(wxPoint(ThirdPosition,8));
149 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
155 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
157 // Adjust the Event text so it is displayed properly.
159 switch(PositionMode){
161 EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
164 EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
167 EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
171 // Refresh the window.
177 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
179 // Change the background of the widget to mark
180 // the entry as selected.
182 this->SetBackgroundColour(wxColor(255,215,0));
183 wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
184 DeselectOthersEvent.SetInt(EntryID);
185 wxPostEvent(DayPanel, DeselectOthersEvent);
189 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
191 this->SetBackgroundColour(wxNullColour);
195 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
197 EntryColour = *ColourIn;
201 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
203 HasAlarm = DisplayValue;
208 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
210 HasHighPriority = DisplayValue;
215 bool XCCalendarDayEntry::GetDisplayAlarm(){
221 bool XCCalendarDayEntry::GetDisplayHighPriority(){
223 return HasHighPriority;
227 int XCCalendarDayEntry::GetID(){