Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Changed SetShowAccountStatus and SetShowCalendarStatus return value from bool to...
[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 wxDEFINE_EVENT(XCCALENDARDAYENTRY_DESELECT, wxCommandEvent);
23 BEGIN_EVENT_TABLE(XCCalendarDayEntry, wxPanel)
24 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
25 EVT_LEFT_UP(XCCalendarDayEntry::LeftClick)
26 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
27 END_EVENT_TABLE()
29 using namespace std;
31 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
32         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
33         dayPanel = parent->GetParent();
34         eventID = id;
35         
36         this->SetMinSize(wxSize(65, 30));
38         // Setup the main panel and main sizer.
39         
40         mainPanel = new wxPanel(this, wxID_ANY, wxPoint(0,0), this->GetSize(), wxTAB_TRAVERSAL|wxSIMPLE_BORDER);
41         mainSizer = new wxBoxSizer( wxVERTICAL );
42                 
43         // Setup the calendar colour.
44         
45         calendarColour = new wxPanel(mainPanel, wxID_ANY, wxPoint(0,0), wxSize(10, 30), wxTAB_TRAVERSAL|wxEXPAND, "Calendar Colour");
46         calendarColour->SetBackgroundColour(wxColour(80, 40, 40, 100));
47                 
48         // Setup the event text.
49                 
50         eventTextData = title.mb_str();
51         eventText = new wxStaticText(mainPanel, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
52         eventTime = new wxStaticText(mainPanel, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
53                 
54         wxFont eventTimeFont = eventTime->GetFont();
55         eventTimeFont.MakeBold();
56         eventTime->SetFont(eventTimeFont);
58         // Setup the images.
59                 
60         wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
61         wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
62                 
63         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
64         alarmIconBitmap = wxBitmap(icons_alert_png, -1);
66         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
67         priorityIconBitmap = wxBitmap(icons_priority_png, -1);
68                 
69         alarmIcon->SetBitmap(alarmIconBitmap);
70         highPriorityIcon->SetBitmap(priorityIconBitmap);
71         
72         // Setup the connections for the control.
73         
74         calendarColour->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
75         alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
76         highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
77         eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
78         eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
79         dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
81         calendarColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
82         alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
83         highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
84         eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
85         eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
86         dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
88         UpdateInformation();
89         
90         // Bind events to the control.
91         
92         Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
93         
94         // Set the control's sizer.
95         
96         this->SetSizer(mainSizer);
97         mainSizer->Add(mainPanel, 0, wxEXPAND, 1);
98 }
100 XCCalendarDayEntry::~XCCalendarDayEntry(){
101         
102         // Destory the controls from the widget.
103         
106 void XCCalendarDayEntry::UpdateInformation(){
108         positionMode = 0;
110         // Check if the high priority icon needs to be displayed.
111         
112         if (hasHighPriority == true){
113                 
114                 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
116                 highPriorityIcon->Show(true);
117                 
118                 positionMode++;
119                 
120         } else {
121                 
122                 highPriorityIcon->Show(false);
123                 
124         }
125         
126         // Check if the alarm icon needs to be displayed.
127         
128         if (hasAlarm == true){
129                 
130                 switch(positionMode){
131                         case 0:
132                                 alarmIcon->SetPosition(wxPoint(firstPosition,7));
133                                 break;
134                         case 1:
135                                 alarmIcon->SetPosition(wxPoint(secondPosition,7));
136                                 break;
137                 }
138                 
139                 alarmIcon->Show(true);
140                 
141                 positionMode++;
142                 
143         } else {
144                 
145                 alarmIcon->Show(false);
146                 
147         }
148         
149         // Now set the text.
150         
151         switch(positionMode){
152                 case 0:
153                         eventText->SetPosition(wxPoint(firstPosition,14));
154                         eventTime->SetPosition(wxPoint(firstPosition,3));
155                         break;
156                 case 1:
157                         eventText->SetPosition(wxPoint(secondPosition,14));
158                         eventTime->SetPosition(wxPoint(firstPosition,3));
159                         break;
160                 case 2:
161                         eventText->SetPosition(wxPoint(thirdPosition,14));
162                         eventTime->SetPosition(wxPoint(firstPosition,3));
163                         break;
164         }
165         
168 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
169         
170         // Adjust the Event text so it is displayed properly.
171         
172         switch(positionMode){
173                 case 0:
174                         eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
175                         eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
176                         break;
177                 case 1:
178                         eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
179                         eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
180                         break;
181                 case 2:
182                         eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
183                         eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
184                         break;
185         }
186         
187         // Resize the main panel.
188         
189         mainPanel->SetSize(this->GetSize());
190         
191         // Refresh the window.
192         
193         this->Refresh();
194         
197 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
198         
199         // Change the background of the widget to mark 
200         // the entry as selected.
201         
202         mainPanel->SetBackgroundColour(wxColor(255,215,0));
203         wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
204         deselectOthersEvent.SetInt(eventID);
205         deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
206         wxPostEvent(dayPanel, deselectOthersEvent);
207         
210 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
211         
212         // Sent an event to the month view control.
213         
214         EventProperties *eventData = new EventProperties;
215         eventData->calendarID = calendarID;
216         eventData->eventID = eventID;
217         
218         wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
219         eventMenu.SetClientData(eventData);
220         eventMenu.SetId(ID_DISPLAYEVENTMENU);
221         wxPostEvent(this->GetParent()->GetParent(), eventMenu);
222         
225 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
226         
227         mainPanel->SetBackgroundColour(wxNullColour);
228         
231 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
232         
233         this->timeHour = timeHour;
234         this->timeMinute = timeMinute;
235         this->timeSecond = timeSecond;
236         
237         string timeOutput = BuildEventTime(timeHour, timeMinute);
238         eventTime->SetLabel(timeOutput);
239         
242 void XCCalendarDayEntry::SetColour(Colour *colourIn){
243         
244         calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha));
245         
248 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
249         
250         hasAlarm = displayValue;
251         UpdateInformation();
252         
255 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
256         
257         hasHighPriority = displayValue;
258         UpdateInformation();    
259         
262 bool XCCalendarDayEntry::GetDisplayAlarm(){
263         
264         return hasAlarm;
265         
268 bool XCCalendarDayEntry::GetDisplayHighPriority(){
269         
270         return hasHighPriority;
271         
274 int XCCalendarDayEntry::GetID(){
275         
276         return eventID;
277         
280 int XCCalendarDayEntry::GetCalendarID(){
281         
282         return calendarID;
283         
286 int XCCalendarDayEntry::GetEventID(){
287         
288         return eventID;
289         
292 int XCCalendarDayEntry::GetAccountID(){
293         
294         return accountID;
295         
298 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
299         
300         string timeOutput;
301         
302         if (timeHour > 12){
303                 
304                 timeOutput += to_string(timeHour - 12);
305                 
306         } else if (timeHour > 0){
307                 
308                 timeOutput += to_string(timeHour);
309                 
310         } else if (timeHour == 0){
311         
312                 timeOutput += to_string(12);
313                 
314         }
315         
316         timeOutput += ":";
317         
318         if (timeMinute < 10){
319                 timeOutput += "0";
320         }       
321         
322         timeOutput += to_string(timeMinute);
323         
324         if (timeHour < 12){
325                 timeOutput += "am";
326         } else {
327                 timeOutput += "pm";
328         }
329         
330         return timeOutput;
331         
334 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
335         
336         this->accountID = accountID;
337         this->calendarID = calendarID;
338         this->eventID = eventID;
339         
342 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
343         
344         this->afterSpacer = afterSpacer;
345         
348 void XCCalendarDayEntry::SetEventName(string eventName){
349         
350         eventText->SetLabel((wxString)eventName);
351         
354 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
355         
356         return afterSpacer;
357         
360 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
361         
362         showAccount = statusInput;
363         
366 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
368         showCalendar = statusInput;
369         
372 bool XCCalendarDayEntry::GetShowAccountStatus(){
373         
374         return showAccount;
375         
378 bool XCCalendarDayEntry::GetShowCalendarStatus(){
380         return showCalendar;
381         
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