Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added events for selecting a calendar event in the XCCalendarDayEntry class
[xestiacalendar/.git] / source / widgets / XCCalendarDayEntry.cpp
1 // XCCalendarDayEntry.cpp - Xestia Calendar XCCalendarDayEntry widget class.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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)
25 END_EVENT_TABLE()
27 using namespace std;
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){
31         
32         DayPanel = parent->GetParent();
33         EntryID = id;
34         
35         this->SetMinSize(wxSize(65, 30));
36         
37         EventTextData = title.mb_str();
38         EventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 8), wxDefaultSize, wxST_ELLIPSIZE_END);
39         
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);
50         
51         UpdateInformation();
52         
53 }
55 XCCalendarDayEntry::~XCCalendarDayEntry(){
56         
57         // Destory the controls from the widget.
58         
59 }
61 void XCCalendarDayEntry::Repaint(){
62         
63         wxPaintDC dc(this);
65         // Get the wxSizerItem for the top date and the entries part.
67         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
68         
69         /*wxRect Test;
70         
71         Test.SetX(this->GetClientRect().GetX());
72         Test.SetY(this->GetClientRect().GetY());
73         Test.SetHeight(this->GetClientRect().GetHeight());
74         Test.SetWidth(this->GetClientRect().GetWidth());
75         
76         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
77         
78         dc.DrawRectangle(this->GetClientRect());
79         
80         // Draw the calendar colour.
81         
82         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
83         dc.SetBrush(wxBrush(wxColor(EntryColour.red,
84                 EntryColour.green,
85                 EntryColour.blue), wxBRUSHSTYLE_SOLID));
86         dc.DrawRectangle(wxRect(1,1,10,28));
87         
88 }
90 void XCCalendarDayEntry::UpdateInformation(){
92         PositionMode = 0;
94         // Check if the high priority icon needs to be displayed.
95         
96         if (HasHighPriority == true){
97                 
98                 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
100                 HighPriorityIcon->Show(true);
101                 
102                 PositionMode++;
103                 
104         } else {
105                 
106                 HighPriorityIcon->Show(false);
107                 
108         }
109         
110         // Check if the alarm icon needs to be displayed.
111         
112         if (HasAlarm == true){
113                 
114                 switch(PositionMode){
115                         case 0:
116                                 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
117                                 break;
118                         case 1:
119                                 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
120                                 break;
121                 }
122                 
123                 AlarmIcon->Show(true);
124                 
125                 PositionMode++;
126                 
127         } else {
128                 
129                 AlarmIcon->Show(false);
130                 
131         }
132         
133         // Now set the text.
134         
135         switch(PositionMode){
136                 case 0:
137                         EventText->SetPosition(wxPoint(FirstPosition,8));
138                         break;
139                 case 1:
140                         EventText->SetPosition(wxPoint(SecondPosition,8));
141                         break;
142                 case 2:
143                         EventText->SetPosition(wxPoint(ThirdPosition,8));
144                         break;
145         }
146         
149 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
151         Repaint();
152         
155 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
156         
157         // Adjust the Event text so it is displayed properly.
158         
159         switch(PositionMode){
160                 case 0:
161                         EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
162                         break;
163                 case 1:
164                         EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
165                         break;
166                 case 2:
167                         EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
168                         break;
169         }
170         
171         // Refresh the window.
172         
173         this->Refresh();
174         
177 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
178         
179         // Change the background of the widget to mark 
180         // the entry as selected.
181         
182         this->SetBackgroundColour(wxColor(255,215,0));
183         wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
184         DeselectOthersEvent.SetInt(EntryID);
185         wxPostEvent(DayPanel, DeselectOthersEvent);
186         
189 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
190         
191         this->SetBackgroundColour(wxNullColour);
192         
195 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
196         
197         EntryColour = *ColourIn;
198         
201 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
202         
203         HasAlarm = DisplayValue;
204         UpdateInformation();
205         
208 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
209         
210         HasHighPriority = DisplayValue;
211         UpdateInformation();    
212         
215 bool XCCalendarDayEntry::GetDisplayAlarm(){
216         
217         return HasAlarm;
218         
221 bool XCCalendarDayEntry::GetDisplayHighPriority(){
222         
223         return HasHighPriority;
224         
227 int XCCalendarDayEntry::GetID(){
228         
229         return EntryID;
230         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy