Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
svrblist: Implemented server blacklist code for Xestia Address Book
[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, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
39         EventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
40                 
41         wxFont eventTimeFont = EventTime->GetFont();
42         eventTimeFont.MakeBold();
43         EventTime->SetFont(eventTimeFont);
45         wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
46         wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
47                 
48         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
49         AlarmIconBitmap = wxBitmap(icons_alert_png, -1);
51         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
52         PriorityIconBitmap = wxBitmap(icons_priority_png, -1);
53                 
54         AlarmIcon->SetBitmap(AlarmIconBitmap);
55         HighPriorityIcon->SetBitmap(PriorityIconBitmap);
57         Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
58         AlarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
59         HighPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
60         EventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61         EventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62         DayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
63         
64         UpdateInformation();
65         
66 }
68 XCCalendarDayEntry::~XCCalendarDayEntry(){
69         
70         // Destory the controls from the widget.
71         
72 }
74 void XCCalendarDayEntry::Repaint(){
75         
76         wxPaintDC dc(this);
78         // Get the wxSizerItem for the top date and the entries part.
80         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
81         
82         /*wxRect Test;
83         
84         Test.SetX(this->GetClientRect().GetX());
85         Test.SetY(this->GetClientRect().GetY());
86         Test.SetHeight(this->GetClientRect().GetHeight());
87         Test.SetWidth(this->GetClientRect().GetWidth());
88         
89         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
90         
91         dc.DrawRectangle(this->GetClientRect());
92         
93         // Draw the calendar colour.
94         
95         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
96         dc.SetBrush(wxBrush(wxColor(EntryColour.red,
97                 EntryColour.green,
98                 EntryColour.blue), wxBRUSHSTYLE_SOLID));
99         dc.DrawRectangle(wxRect(1,1,10,28));
100         
103 void XCCalendarDayEntry::UpdateInformation(){
105         PositionMode = 0;
107         // Check if the high priority icon needs to be displayed.
108         
109         if (HasHighPriority == true){
110                 
111                 HighPriorityIcon->SetPosition(wxPoint(FirstPosition,7));
113                 HighPriorityIcon->Show(true);
114                 
115                 PositionMode++;
116                 
117         } else {
118                 
119                 HighPriorityIcon->Show(false);
120                 
121         }
122         
123         // Check if the alarm icon needs to be displayed.
124         
125         if (HasAlarm == true){
126                 
127                 switch(PositionMode){
128                         case 0:
129                                 AlarmIcon->SetPosition(wxPoint(FirstPosition,7));
130                                 break;
131                         case 1:
132                                 AlarmIcon->SetPosition(wxPoint(SecondPosition,7));
133                                 break;
134                 }
135                 
136                 AlarmIcon->Show(true);
137                 
138                 PositionMode++;
139                 
140         } else {
141                 
142                 AlarmIcon->Show(false);
143                 
144         }
145         
146         // Now set the text.
147         
148         switch(PositionMode){
149                 case 0:
150                         EventText->SetPosition(wxPoint(FirstPosition,14));
151                         EventTime->SetPosition(wxPoint(FirstPosition,3));
152                         break;
153                 case 1:
154                         EventText->SetPosition(wxPoint(SecondPosition,14));
155                         EventTime->SetPosition(wxPoint(FirstPosition,3));
156                         break;
157                 case 2:
158                         EventText->SetPosition(wxPoint(ThirdPosition,14));
159                         EventTime->SetPosition(wxPoint(FirstPosition,3));
160                         break;
161         }
162         
165 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &PaintEvent){
167         Repaint();
168         
171 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &SizeEvent){
172         
173         // Adjust the Event text so it is displayed properly.
174         
175         switch(PositionMode){
176                 case 0:
177                         EventText->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
178                         EventTime->SetSize(wxSize((this->GetClientRect().width - FirstPosition - 5),15));
179                         break;
180                 case 1:
181                         EventText->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
182                         EventTime->SetSize(wxSize((this->GetClientRect().width - SecondPosition - 5),15));
183                         break;
184                 case 2:
185                         EventText->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),14));
186                         EventTime->SetSize(wxSize((this->GetClientRect().width - ThirdPosition - 5),15));
187                         break;
188         }
189         
190         // Refresh the window.
191         
192         this->Refresh();
193         
196 void XCCalendarDayEntry::LeftClick(wxMouseEvent &MouseEvent){
197         
198         // Change the background of the widget to mark 
199         // the entry as selected.
200         
201         this->SetBackgroundColour(wxColor(255,215,0));
202         wxCommandEvent DeselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
203         DeselectOthersEvent.SetInt(entryID);
204         DeselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
205         wxPostEvent(DayPanel, DeselectOthersEvent);
206         
209 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
210         
211         this->SetBackgroundColour(wxNullColour);
212         
215 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
216         
217         this->timeHour = timeHour;
218         this->timeMinute = timeMinute;
219         this->timeSecond = timeSecond;
220         
221         string timeOutput = BuildEventTime(timeHour, timeMinute);
222         EventTime->SetLabel(timeOutput);
223         
226 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
227         
228         EntryColour = *ColourIn;
229         Repaint();
230         
233 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
234         
235         HasAlarm = DisplayValue;
236         UpdateInformation();
237         
240 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
241         
242         HasHighPriority = DisplayValue;
243         UpdateInformation();    
244         
247 bool XCCalendarDayEntry::GetDisplayAlarm(){
248         
249         return HasAlarm;
250         
253 bool XCCalendarDayEntry::GetDisplayHighPriority(){
254         
255         return HasHighPriority;
256         
259 int XCCalendarDayEntry::GetID(){
260         
261         return entryID;
262         
265 int XCCalendarDayEntry::GetCalendarID(){
266         
267         return calendarID;
268         
271 int XCCalendarDayEntry::GetAccountID(){
272         
273         return accountID;
274         
277 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
278         
279         string timeOutput;
280         
281         if (timeHour > 12){
282                 
283                 timeOutput += to_string(timeHour - 12);
284                 
285         } else if (timeHour > 0){
286                 
287                 timeOutput += to_string(timeHour);
288                 
289         } else if (timeHour == 0){
290         
291                 timeOutput += to_string(12);
292                 
293         }
294         
295         timeOutput += ":";
296         
297         if (timeMinute < 10){
298                 timeOutput += "0";
299         }       
300         
301         timeOutput += to_string(timeMinute);
302         
303         if (timeHour < 12){
304                 timeOutput += "am";
305         } else {
306                 timeOutput += "pm";
307         }
308         
309         return timeOutput;
310         
313 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int entryID){
314         
315         this->accountID = accountID;
316         this->calendarID = calendarID;
317         this->entryID = entryID;
318         
321 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
322         
323         this->afterSpacer = afterSpacer;
324         
327 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
328         
329         return afterSpacer;
330         
333 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
334         
335         showAccount = statusInput;
336         
339 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
341         showCalendar = statusInput;
342         
345 bool XCCalendarDayEntry::GetShowAccountStatus(){
346         
347         return showAccount;
348         
351 bool XCCalendarDayEntry::GetShowCalendarStatus(){
353         return showCalendar;
354         
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