Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted code in widgets directory
[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_UP(XCCalendarDayEntry::LeftClick)
25 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
26 END_EVENT_TABLE()
28 using namespace std;
30 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
31         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
32         
33         dayPanel = parent->GetParent();
34         eventID = id;
35         
36         this->SetMinSize(wxSize(65, 30));
37         
38         eventTextData = title.mb_str();
39         eventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
40         eventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
41                 
42         wxFont eventTimeFont = eventTime->GetFont();
43         eventTimeFont.MakeBold();
44         eventTime->SetFont(eventTimeFont);
46         wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
47         wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
48                 
49         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
50         alarmIconBitmap = wxBitmap(icons_alert_png, -1);
52         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
53         priorityIconBitmap = wxBitmap(icons_priority_png, -1);
54                 
55         alarmIcon->SetBitmap(alarmIconBitmap);
56         highPriorityIcon->SetBitmap(priorityIconBitmap);
58         Connect(ID_ENTRYDESELECT, XCCALENDARDAYENTRY_DESELECT, wxCommandEventHandler(XCCalendarDayEntry::Deselect));
59         
60         alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61         highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62         eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
63         eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
64         dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
65         
66         alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
67         highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
68         eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
69         eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
70         dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
72         UpdateInformation();
73         
74 }
76 XCCalendarDayEntry::~XCCalendarDayEntry(){
77         
78         // Destory the controls from the widget.
79         
80 }
82 void XCCalendarDayEntry::Repaint(){
83         
84         wxPaintDC dc(this);
86         // Get the wxSizerItem for the top date and the entries part.
88         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
89         
90         /*wxRect Test;
91         
92         Test.SetX(this->GetClientRect().GetX());
93         Test.SetY(this->GetClientRect().GetY());
94         Test.SetHeight(this->GetClientRect().GetHeight());
95         Test.SetWidth(this->GetClientRect().GetWidth());
96         
97         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
98         
99         dc.DrawRectangle(this->GetClientRect());
100         
101         // Draw the calendar colour.
102         
103         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
104         dc.SetBrush(wxBrush(wxColor(entryColour.red,
105                 entryColour.green,
106                 entryColour.blue), wxBRUSHSTYLE_SOLID));
107         dc.DrawRectangle(wxRect(1,1,10,28));
108         
111 void XCCalendarDayEntry::UpdateInformation(){
113         positionMode = 0;
115         // Check if the high priority icon needs to be displayed.
116         
117         if (hasHighPriority == true){
118                 
119                 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
121                 highPriorityIcon->Show(true);
122                 
123                 positionMode++;
124                 
125         } else {
126                 
127                 highPriorityIcon->Show(false);
128                 
129         }
130         
131         // Check if the alarm icon needs to be displayed.
132         
133         if (hasAlarm == true){
134                 
135                 switch(positionMode){
136                         case 0:
137                                 alarmIcon->SetPosition(wxPoint(firstPosition,7));
138                                 break;
139                         case 1:
140                                 alarmIcon->SetPosition(wxPoint(secondPosition,7));
141                                 break;
142                 }
143                 
144                 alarmIcon->Show(true);
145                 
146                 positionMode++;
147                 
148         } else {
149                 
150                 alarmIcon->Show(false);
151                 
152         }
153         
154         // Now set the text.
155         
156         switch(positionMode){
157                 case 0:
158                         eventText->SetPosition(wxPoint(firstPosition,14));
159                         eventTime->SetPosition(wxPoint(firstPosition,3));
160                         break;
161                 case 1:
162                         eventText->SetPosition(wxPoint(secondPosition,14));
163                         eventTime->SetPosition(wxPoint(firstPosition,3));
164                         break;
165                 case 2:
166                         eventText->SetPosition(wxPoint(thirdPosition,14));
167                         eventTime->SetPosition(wxPoint(firstPosition,3));
168                         break;
169         }
170         
173 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &paintEvent){
175         Repaint();
176         
179 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
180         
181         // Adjust the Event text so it is displayed properly.
182         
183         switch(positionMode){
184                 case 0:
185                         eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
186                         eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
187                         break;
188                 case 1:
189                         eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
190                         eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
191                         break;
192                 case 2:
193                         eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
194                         eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
195                         break;
196         }
197         
198         // Refresh the window.
199         
200         this->Refresh();
201         
204 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
205         
206         // Change the background of the widget to mark 
207         // the entry as selected.
208         
209         this->SetBackgroundColour(wxColor(255,215,0));
210         wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
211         deselectOthersEvent.SetInt(eventID);
212         deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
213         wxPostEvent(dayPanel, deselectOthersEvent);
214         
217 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
218         
219         // Sent an event to the month view control.
220         
221         EventProperties *eventData = new EventProperties;
222         eventData->calendarID = calendarID;
223         eventData->eventID = eventID;
224         
225         wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
226         eventMenu.SetClientData(eventData);
227         eventMenu.SetId(ID_DISPLAYEVENTMENU);
228         wxPostEvent(this->GetParent()->GetParent(), eventMenu);
229         
232 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
233         
234         this->SetBackgroundColour(wxNullColour);
235         
238 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
239         
240         this->timeHour = timeHour;
241         this->timeMinute = timeMinute;
242         this->timeSecond = timeSecond;
243         
244         string timeOutput = BuildEventTime(timeHour, timeMinute);
245         eventTime->SetLabel(timeOutput);
246         
249 void XCCalendarDayEntry::SetColour(Colour *ColourIn){
250         
251         entryColour = *colourIn;
252         Repaint();
253         
256 void XCCalendarDayEntry::SetDisplayAlarm(bool DisplayValue){
257         
258         hasAlarm = displayValue;
259         UpdateInformation();
260         
263 void XCCalendarDayEntry::SetDisplayHighPriority(bool DisplayValue){
264         
265         hasHighPriority = displayValue;
266         UpdateInformation();    
267         
270 bool XCCalendarDayEntry::GetDisplayAlarm(){
271         
272         return hasAlarm;
273         
276 bool XCCalendarDayEntry::GetDisplayHighPriority(){
277         
278         return hasHighPriority;
279         
282 int XCCalendarDayEntry::GetID(){
283         
284         return eventID;
285         
288 int XCCalendarDayEntry::GetCalendarID(){
289         
290         return calendarID;
291         
294 int XCCalendarDayEntry::GetEventID(){
295         
296         return eventID;
297         
300 int XCCalendarDayEntry::GetAccountID(){
301         
302         return accountID;
303         
306 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
307         
308         string timeOutput;
309         
310         if (timeHour > 12){
311                 
312                 timeOutput += to_string(timeHour - 12);
313                 
314         } else if (timeHour > 0){
315                 
316                 timeOutput += to_string(timeHour);
317                 
318         } else if (timeHour == 0){
319         
320                 timeOutput += to_string(12);
321                 
322         }
323         
324         timeOutput += ":";
325         
326         if (timeMinute < 10){
327                 timeOutput += "0";
328         }       
329         
330         timeOutput += to_string(timeMinute);
331         
332         if (timeHour < 12){
333                 timeOutput += "am";
334         } else {
335                 timeOutput += "pm";
336         }
337         
338         return timeOutput;
339         
342 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
343         
344         this->accountID = accountID;
345         this->calendarID = calendarID;
346         this->eventID = eventID;
347         
350 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
351         
352         this->afterSpacer = afterSpacer;
353         
356 void XCCalendarDayEntry::SetEventName(string eventName){
357         
358         eventText->SetLabel((wxString)eventName);
359         
362 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
363         
364         return afterSpacer;
365         
368 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
369         
370         showAccount = statusInput;
371         
374 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
376         showCalendar = statusInput;
377         
380 bool XCCalendarDayEntry::GetShowAccountStatus(){
381         
382         return showAccount;
383         
386 bool XCCalendarDayEntry::GetShowCalendarStatus(){
388         return showCalendar;
389         
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