Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Implemented UTF8 support in DeleteCalendar function
[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         this->Refresh();
251 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
252         
253         hasAlarm = displayValue;
254         UpdateInformation();
255         
258 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
259         
260         hasHighPriority = displayValue;
261         UpdateInformation();    
262         
265 bool XCCalendarDayEntry::GetDisplayAlarm(){
266         
267         return hasAlarm;
268         
271 bool XCCalendarDayEntry::GetDisplayHighPriority(){
272         
273         return hasHighPriority;
274         
277 int XCCalendarDayEntry::GetID(){
278         
279         return eventID;
280         
283 int XCCalendarDayEntry::GetCalendarID(){
284         
285         return calendarID;
286         
289 int XCCalendarDayEntry::GetEventID(){
290         
291         return eventID;
292         
295 int XCCalendarDayEntry::GetAccountID(){
296         
297         return accountID;
298         
301 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
302         
303         string timeOutput;
304         
305         if (timeHour > 12){
306                 
307                 timeOutput += to_string(timeHour - 12);
308                 
309         } else if (timeHour > 0){
310                 
311                 timeOutput += to_string(timeHour);
312                 
313         } else if (timeHour == 0){
314         
315                 timeOutput += to_string(12);
316                 
317         }
318         
319         timeOutput += ":";
320         
321         if (timeMinute < 10){
322                 timeOutput += "0";
323         }       
324         
325         timeOutput += to_string(timeMinute);
326         
327         if (timeHour < 12){
328                 timeOutput += "am";
329         } else {
330                 timeOutput += "pm";
331         }
332         
333         return timeOutput;
334         
337 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
338         
339         this->accountID = accountID;
340         this->calendarID = calendarID;
341         this->eventID = eventID;
342         
345 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
346         
347         this->afterSpacer = afterSpacer;
348         
351 void XCCalendarDayEntry::SetEventName(string eventName){
352         
353         eventText->SetLabel((wxString)eventName);
354         
357 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
358         
359         return afterSpacer;
360         
363 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
364         
365         showAccount = statusInput;
366         
369 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
371         showCalendar = statusInput;
372         
375 bool XCCalendarDayEntry::GetShowAccountStatus(){
376         
377         return showAccount;
378         
381 bool XCCalendarDayEntry::GetShowCalendarStatus(){
383         return showCalendar;
384         
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