Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XCCalendarDayEntry: Refresh panel on selection and deselection.
[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         this->Refresh();
211 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
212         
213         // Sent an event to the month view control.
214         
215         EventProperties *eventData = new EventProperties;
216         eventData->calendarID = calendarID;
217         eventData->eventID = eventID;
218         
219         wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
220         eventMenu.SetClientData(eventData);
221         eventMenu.SetId(ID_DISPLAYEVENTMENU);
222         wxPostEvent(this->GetParent()->GetParent(), eventMenu);
223         
226 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
227         
228         mainPanel->SetBackgroundColour(wxNullColour);
229         this->Refresh();
230         
233 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
234         
235         this->timeHour = timeHour;
236         this->timeMinute = timeMinute;
237         this->timeSecond = timeSecond;
238         
239         string timeOutput = BuildEventTime(timeHour, timeMinute);
240         eventTime->SetLabel(timeOutput);
241         
244 void XCCalendarDayEntry::SetColour(Colour *colourIn){
245         
246         calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha));
247         
250 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
251         
252         hasAlarm = displayValue;
253         UpdateInformation();
254         
257 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
258         
259         hasHighPriority = displayValue;
260         UpdateInformation();    
261         
264 bool XCCalendarDayEntry::GetDisplayAlarm(){
265         
266         return hasAlarm;
267         
270 bool XCCalendarDayEntry::GetDisplayHighPriority(){
271         
272         return hasHighPriority;
273         
276 int XCCalendarDayEntry::GetID(){
277         
278         return eventID;
279         
282 int XCCalendarDayEntry::GetCalendarID(){
283         
284         return calendarID;
285         
288 int XCCalendarDayEntry::GetEventID(){
289         
290         return eventID;
291         
294 int XCCalendarDayEntry::GetAccountID(){
295         
296         return accountID;
297         
300 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
301         
302         string timeOutput;
303         
304         if (timeHour > 12){
305                 
306                 timeOutput += to_string(timeHour - 12);
307                 
308         } else if (timeHour > 0){
309                 
310                 timeOutput += to_string(timeHour);
311                 
312         } else if (timeHour == 0){
313         
314                 timeOutput += to_string(12);
315                 
316         }
317         
318         timeOutput += ":";
319         
320         if (timeMinute < 10){
321                 timeOutput += "0";
322         }       
323         
324         timeOutput += to_string(timeMinute);
325         
326         if (timeHour < 12){
327                 timeOutput += "am";
328         } else {
329                 timeOutput += "pm";
330         }
331         
332         return timeOutput;
333         
336 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
337         
338         this->accountID = accountID;
339         this->calendarID = calendarID;
340         this->eventID = eventID;
341         
344 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
345         
346         this->afterSpacer = afterSpacer;
347         
350 void XCCalendarDayEntry::SetEventName(string eventName){
351         
352         eventText->SetLabel((wxString)eventName);
353         
356 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
357         
358         return afterSpacer;
359         
362 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
363         
364         showAccount = statusInput;
365         
368 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
370         showCalendar = statusInput;
371         
374 bool XCCalendarDayEntry::GetShowAccountStatus(){
375         
376         return showAccount;
377         
380 bool XCCalendarDayEntry::GetShowCalendarStatus(){
382         return showCalendar;
383         
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