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)
33 Connect(wxID_ANY, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
35 DayPanel = parent->GetParent();
38 this->SetMinSize(wxSize(65, 30));
40 EventTextData = title.mb_str();
41 EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END);
43 AlarmIconBitmap.LoadFile("AlertIcon.png", wxBITMAP_DEFAULT_TYPE);
44 PriorityIconBitmap.LoadFile("PriorityIcon.png", wxBITMAP_DEFAULT_TYPE);
46 AlarmIcon->SetBitmap(AlarmIconBitmap);
47 HighPriorityIcon->SetBitmap(PriorityIconBitmap);
53 XCCalendarDayEntry::~XCCalendarDayEntry(){
55 // Destory the controls from the widget.
59 void XCCalendarDayEntry::Repaint(){
63 // Get the wxSizerItem for the top date and the entries part.
65 dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
69 Test.SetX(this->GetClientRect().GetX());
70 Test.SetY(this->GetClientRect().GetY());
71 Test.SetHeight(this->GetClientRect().GetHeight());
72 Test.SetWidth(this->GetClientRect().GetWidth());
74 cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
76 dc.DrawRectangle(this->GetClientRect());
78 // Draw the calendar colour.
80 dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
81 dc.SetBrush(wxBrush(wxColor(EntryColour.red,
83 EntryColour.blue), wxBRUSHSTYLE_SOLID));
84 dc.DrawRectangle(wxRect(1,1,10,28));
88 void XCCalendarDayEntry::UpdateInformation(){
92 // Check if the high priority icon needs to be displayed.
94 if (HasHighPriority == true){
96 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
98 HighPriorityIcon->Show(true);
104 HighPriorityIcon->Show(false);
108 // Check if the alarm icon needs to be displayed.
110 if (HasAlarm == true){
112 switch(PositionMode){
114 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
117 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
121 AlarmIcon->Show(true);
127 AlarmIcon->Show(false);
133 switch(PositionMode){
135 EventText->SetPosition(wxPoint(FirstPosition,8));
138 EventText->SetPosition(wxPoint(SecondPosition,8));
141 EventText->SetPosition(wxPoint(ThirdPosition,8));
147 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent)
154 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)
180 // Change the background of the widget to mark
181 // the entry as selected.
183 this->SetBackgroundColour(wxColor(255,215,0));
184 wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
185 DeselectOthersEvent.SetInt(EntryID);
186 wxPostEvent(DayPanel, DeselectOthersEvent);
190 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
192 this->SetBackgroundColour(wxNullColour);
196 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
198 EntryColour = *ColourIn;
202 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
204 HasAlarm = DisplayValue;
209 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
211 HasHighPriority = DisplayValue;
216 bool XCCalendarDayEntry::GetDisplayAlarm(){
222 bool XCCalendarDayEntry::GetDisplayHighPriority(){
224 return HasHighPriority;
228 int XCCalendarDayEntry::GetID(){