Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Add files for Win32 support
[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         
104         // Disconnect and unbind.
105         
106         calendarColour->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
107         alarmIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
108         highPriorityIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
109         eventText->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
110         eventTime->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
111         dayPanel->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
113         calendarColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
114         alarmIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
115         highPriorityIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
116         eventText->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
117         eventTime->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
118         dayPanel->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
119         
120         Unbind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
121         
122         // Delete the controls.
123         
124         mainSizer->Clear();
125         
126         delete eventText;
127         eventText = nullptr;
128         
129         delete eventTime;
130         eventTime = nullptr;
131         
132         delete calendarColour;
133         calendarColour = nullptr;
134         
135         delete mainPanel;
136         mainPanel = nullptr;
137         
138         delete highPriorityIcon;
139         delete alarmIcon;
140         
141         this->SetSizer(nullptr, true);
142         
145 void XCCalendarDayEntry::UpdateInformation(){
147         positionMode = 0;
149         // Check if the high priority icon needs to be displayed.
150         
151         if (hasHighPriority == true){
152                 
153                 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
155                 highPriorityIcon->Show(true);
156                 
157                 positionMode++;
158                 
159         } else {
160                 
161                 highPriorityIcon->Show(false);
162                 
163         }
164         
165         // Check if the alarm icon needs to be displayed.
166         
167         if (hasAlarm == true){
168                 
169                 switch(positionMode){
170                         case 0:
171                                 alarmIcon->SetPosition(wxPoint(firstPosition,7));
172                                 break;
173                         case 1:
174                                 alarmIcon->SetPosition(wxPoint(secondPosition,7));
175                                 break;
176                 }
177                 
178                 alarmIcon->Show(true);
179                 
180                 positionMode++;
181                 
182         } else {
183                 
184                 alarmIcon->Show(false);
185                 
186         }
187         
188         // Now set the text.
189         
190         switch(positionMode){
191                 case 0:
192                         eventText->SetPosition(wxPoint(firstPosition,14));
193                         eventTime->SetPosition(wxPoint(firstPosition,3));
194                         break;
195                 case 1:
196                         eventText->SetPosition(wxPoint(secondPosition,14));
197                         eventTime->SetPosition(wxPoint(firstPosition,3));
198                         break;
199                 case 2:
200                         eventText->SetPosition(wxPoint(thirdPosition,14));
201                         eventTime->SetPosition(wxPoint(firstPosition,3));
202                         break;
203         }
204         
207 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
208         
209         // Adjust the Event text so it is displayed properly.
210         
211         switch(positionMode){
212                 case 0:
213                         eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
214                         eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
215                         break;
216                 case 1:
217                         eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
218                         eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
219                         break;
220                 case 2:
221                         eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
222                         eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
223                         break;
224         }
225         
226         // Resize the main panel.
227         
228         mainPanel->SetSize(this->GetSize());
229         
230         // Refresh the window.
231         
232         this->Refresh();
233         
236 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
237         
238         // Change the background of the widget to mark 
239         // the entry as selected.
240         
241         mainPanel->SetBackgroundColour(wxColor(255,215,0));
242         wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
243         deselectOthersEvent.SetInt(eventID);
244         deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
245         wxPostEvent(dayPanel, deselectOthersEvent);
246         this->Refresh();
250 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
251         
252         // Sent an event to the month view control.
253         
254         EventProperties *eventData = new EventProperties;
255         eventData->calendarID = calendarID;
256         eventData->eventID = eventID;
257         
258         wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
259         eventMenu.SetClientData(eventData);
260         eventMenu.SetId(ID_DISPLAYEVENTMENU);
261         wxPostEvent(this->GetParent()->GetParent(), eventMenu);
262         
265 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
266         
267         mainPanel->SetBackgroundColour(wxNullColour);
268         this->Refresh();
269         
272 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
273         
274         this->timeHour = timeHour;
275         this->timeMinute = timeMinute;
276         this->timeSecond = timeSecond;
277         
278         string timeOutput = BuildEventTime(timeHour, timeMinute);
279         eventTime->SetLabel(timeOutput);
280         
283 void XCCalendarDayEntry::SetColour(Colour *colourIn){
284         
285         calendarColour->SetBackgroundColour(wxColour(colourIn->red, colourIn->green, colourIn->blue, colourIn->alpha));
286         this->Refresh();
290 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
291         
292         hasAlarm = displayValue;
293         UpdateInformation();
294         
297 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
298         
299         hasHighPriority = displayValue;
300         UpdateInformation();    
301         
304 bool XCCalendarDayEntry::GetDisplayAlarm(){
305         
306         return hasAlarm;
307         
310 bool XCCalendarDayEntry::GetDisplayHighPriority(){
311         
312         return hasHighPriority;
313         
316 int XCCalendarDayEntry::GetID(){
317         
318         return eventID;
319         
322 int XCCalendarDayEntry::GetCalendarID(){
323         
324         return calendarID;
325         
328 int XCCalendarDayEntry::GetEventID(){
329         
330         return eventID;
331         
334 int XCCalendarDayEntry::GetAccountID(){
335         
336         return accountID;
337         
340 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
341         
342         string timeOutput;
343         
344         if (timeHour > 12){
345                 
346                 timeOutput += to_string(timeHour - 12);
347                 
348         } else if (timeHour > 0){
349                 
350                 timeOutput += to_string(timeHour);
351                 
352         } else if (timeHour == 0){
353         
354                 timeOutput += to_string(12);
355                 
356         }
357         
358         timeOutput += ":";
359         
360         if (timeMinute < 10){
361                 timeOutput += "0";
362         }       
363         
364         timeOutput += to_string(timeMinute);
365         
366         if (timeHour < 12){
367                 timeOutput += "am";
368         } else {
369                 timeOutput += "pm";
370         }
371         
372         return timeOutput;
373         
376 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
377         
378         this->accountID = accountID;
379         this->calendarID = calendarID;
380         this->eventID = eventID;
381         
384 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
385         
386         this->afterSpacer = afterSpacer;
387         
390 void XCCalendarDayEntry::SetEventName(string eventName){
391         
392         eventText->SetLabel(wxString(eventName));
393         
396 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
397         
398         return afterSpacer;
399         
402 void XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
403         
404         showAccount = statusInput;
405         
408 void XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
410         showCalendar = statusInput;
411         
414 bool XCCalendarDayEntry::GetShowAccountStatus(){
415         
416         return showAccount;
417         
420 bool XCCalendarDayEntry::GetShowCalendarStatus(){
422         return showCalendar;
423         
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