Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Events: Now using wxDEFINE_EVENT, wxDECLARE_EVENT and Bind
[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_PAINT(XCCalendarDayEntry::PaintFrameEvent)
25 EVT_SIZE(XCCalendarDayEntry::ResizeFrameEvent)
26 EVT_LEFT_UP(XCCalendarDayEntry::LeftClick)
27 EVT_RIGHT_UP(XCCalendarDayEntry::RightClick)
28 END_EVENT_TABLE()
30 using namespace std;
32 XCCalendarDayEntry::XCCalendarDayEntry(wxWindow* parent, const wxString& title, const wxPoint& pos, const wxSize& size, const int id)
33         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
34         dayPanel = parent->GetParent();
35         eventID = id;
36         
37         this->SetMinSize(wxSize(65, 30));
38         
39         eventTextData = title.mb_str();
40         eventText = new wxStaticText(this, wxID_ANY, title, wxPoint(49, 14), wxDefaultSize, wxST_ELLIPSIZE_END);
41         eventTime = new wxStaticText(this, wxID_ANY, wxT("Time"), wxPoint(49,3), wxDefaultSize, 0);
42                 
43         wxFont eventTimeFont = eventTime->GetFont();
44         eventTimeFont.MakeBold();
45         eventTime->SetFont(eventTimeFont);
47         wxMemoryInputStream alerticon(icons_alert_png, sizeof(icons_alert_png));
48         wxMemoryInputStream priorityicon(icons_priority_png, sizeof(icons_priority_png));
49                 
50         wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
51         alarmIconBitmap = wxBitmap(icons_alert_png, -1);
53         wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
54         priorityIconBitmap = wxBitmap(icons_priority_png, -1);
55                 
56         alarmIcon->SetBitmap(alarmIconBitmap);
57         highPriorityIcon->SetBitmap(priorityIconBitmap);
58         
59         alarmIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
60         highPriorityIcon->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
61         eventText->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
62         eventTime->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
63         dayPanel->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this);
64         
65         alarmIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
66         highPriorityIcon->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
67         eventText->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
68         eventTime->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
69         dayPanel->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this);
71         UpdateInformation();
72         
73         // Bind events to the control.
74         
75         Bind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT);
76 }
78 XCCalendarDayEntry::~XCCalendarDayEntry(){
79         
80         // Destory the controls from the widget.
81         
82 }
84 void XCCalendarDayEntry::Repaint(){
85         
86         wxPaintDC dc(this);
88         // Get the wxSizerItem for the top date and the entries part.
90         dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
91         
92         /*wxRect Test;
93         
94         Test.SetX(this->GetClientRect().GetX());
95         Test.SetY(this->GetClientRect().GetY());
96         Test.SetHeight(this->GetClientRect().GetHeight());
97         Test.SetWidth(this->GetClientRect().GetWidth());
98         
99         cout << Test.GetX() << "|" << Test.GetY() << "|" << Test.GetHeight() << "|" << Test.GetWidth() << "|" << endl;*/
100         
101         dc.DrawRectangle(this->GetClientRect());
102         
103         // Draw the calendar colour.
104         
105         dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
106         dc.SetBrush(wxBrush(wxColor(entryColour.red,
107                 entryColour.green,
108                 entryColour.blue), wxBRUSHSTYLE_SOLID));
109         dc.DrawRectangle(wxRect(1,1,10,28));
110         
113 void XCCalendarDayEntry::UpdateInformation(){
115         positionMode = 0;
117         // Check if the high priority icon needs to be displayed.
118         
119         if (hasHighPriority == true){
120                 
121                 highPriorityIcon->SetPosition(wxPoint(firstPosition,7));
123                 highPriorityIcon->Show(true);
124                 
125                 positionMode++;
126                 
127         } else {
128                 
129                 highPriorityIcon->Show(false);
130                 
131         }
132         
133         // Check if the alarm icon needs to be displayed.
134         
135         if (hasAlarm == true){
136                 
137                 switch(positionMode){
138                         case 0:
139                                 alarmIcon->SetPosition(wxPoint(firstPosition,7));
140                                 break;
141                         case 1:
142                                 alarmIcon->SetPosition(wxPoint(secondPosition,7));
143                                 break;
144                 }
145                 
146                 alarmIcon->Show(true);
147                 
148                 positionMode++;
149                 
150         } else {
151                 
152                 alarmIcon->Show(false);
153                 
154         }
155         
156         // Now set the text.
157         
158         switch(positionMode){
159                 case 0:
160                         eventText->SetPosition(wxPoint(firstPosition,14));
161                         eventTime->SetPosition(wxPoint(firstPosition,3));
162                         break;
163                 case 1:
164                         eventText->SetPosition(wxPoint(secondPosition,14));
165                         eventTime->SetPosition(wxPoint(firstPosition,3));
166                         break;
167                 case 2:
168                         eventText->SetPosition(wxPoint(thirdPosition,14));
169                         eventTime->SetPosition(wxPoint(firstPosition,3));
170                         break;
171         }
172         
175 void XCCalendarDayEntry::PaintFrameEvent(wxPaintEvent &paintEvent){
177         Repaint();
178         
181 void XCCalendarDayEntry::ResizeFrameEvent(wxSizeEvent &sizeEvent){
182         
183         // Adjust the Event text so it is displayed properly.
184         
185         switch(positionMode){
186                 case 0:
187                         eventText->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
188                         eventTime->SetSize(wxSize((this->GetClientRect().width - firstPosition - 5),15));
189                         break;
190                 case 1:
191                         eventText->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
192                         eventTime->SetSize(wxSize((this->GetClientRect().width - secondPosition - 5),15));
193                         break;
194                 case 2:
195                         eventText->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),14));
196                         eventTime->SetSize(wxSize((this->GetClientRect().width - thirdPosition - 5),15));
197                         break;
198         }
199         
200         // Refresh the window.
201         
202         this->Refresh();
203         
206 void XCCalendarDayEntry::LeftClick(wxMouseEvent &mouseEvent){
207         
208         // Change the background of the widget to mark 
209         // the entry as selected.
210         
211         this->SetBackgroundColour(wxColor(255,215,0));
212         wxCommandEvent deselectOthersEvent(XCCALENDARDAY_DESELECTOTHERENTRIES);
213         deselectOthersEvent.SetInt(eventID);
214         deselectOthersEvent.SetId(ID_DESELECTOTHERENTRIES);
215         wxPostEvent(dayPanel, deselectOthersEvent);
216         
219 void XCCalendarDayEntry::RightClick(wxMouseEvent &MouseEvent){
220         
221         // Sent an event to the month view control.
222         
223         EventProperties *eventData = new EventProperties;
224         eventData->calendarID = calendarID;
225         eventData->eventID = eventID;
226         
227         wxCommandEvent eventMenu(XCCALENDARMONTH_DISPLAYEVENTMENU);
228         eventMenu.SetClientData(eventData);
229         eventMenu.SetId(ID_DISPLAYEVENTMENU);
230         wxPostEvent(this->GetParent()->GetParent(), eventMenu);
231         
234 void XCCalendarDayEntry::Deselect(wxCommandEvent &DeselectEvent){
235         
236         this->SetBackgroundColour(wxNullColour);
237         
240 void XCCalendarDayEntry::SetTime(int timeHour, int timeMinute, int timeSecond){
241         
242         this->timeHour = timeHour;
243         this->timeMinute = timeMinute;
244         this->timeSecond = timeSecond;
245         
246         string timeOutput = BuildEventTime(timeHour, timeMinute);
247         eventTime->SetLabel(timeOutput);
248         
251 void XCCalendarDayEntry::SetColour(Colour *colourIn){
252         
253         entryColour = *colourIn;
254         Repaint();
255         
258 void XCCalendarDayEntry::SetDisplayAlarm(bool displayValue){
259         
260         hasAlarm = displayValue;
261         UpdateInformation();
262         
265 void XCCalendarDayEntry::SetDisplayHighPriority(bool displayValue){
266         
267         hasHighPriority = displayValue;
268         UpdateInformation();    
269         
272 bool XCCalendarDayEntry::GetDisplayAlarm(){
273         
274         return hasAlarm;
275         
278 bool XCCalendarDayEntry::GetDisplayHighPriority(){
279         
280         return hasHighPriority;
281         
284 int XCCalendarDayEntry::GetID(){
285         
286         return eventID;
287         
290 int XCCalendarDayEntry::GetCalendarID(){
291         
292         return calendarID;
293         
296 int XCCalendarDayEntry::GetEventID(){
297         
298         return eventID;
299         
302 int XCCalendarDayEntry::GetAccountID(){
303         
304         return accountID;
305         
308 string XCCalendarDayEntry::BuildEventTime(int timeHour, int timeMinute){
309         
310         string timeOutput;
311         
312         if (timeHour > 12){
313                 
314                 timeOutput += to_string(timeHour - 12);
315                 
316         } else if (timeHour > 0){
317                 
318                 timeOutput += to_string(timeHour);
319                 
320         } else if (timeHour == 0){
321         
322                 timeOutput += to_string(12);
323                 
324         }
325         
326         timeOutput += ":";
327         
328         if (timeMinute < 10){
329                 timeOutput += "0";
330         }       
331         
332         timeOutput += to_string(timeMinute);
333         
334         if (timeHour < 12){
335                 timeOutput += "am";
336         } else {
337                 timeOutput += "pm";
338         }
339         
340         return timeOutput;
341         
344 void XCCalendarDayEntry::SetEntryIDs(int accountID, int calendarID, int eventID){
345         
346         this->accountID = accountID;
347         this->calendarID = calendarID;
348         this->eventID = eventID;
349         
352 void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){
353         
354         this->afterSpacer = afterSpacer;
355         
358 void XCCalendarDayEntry::SetEventName(string eventName){
359         
360         eventText->SetLabel((wxString)eventName);
361         
364 wxSizerItem* XCCalendarDayEntry::GetAfterSpacer(){
365         
366         return afterSpacer;
367         
370 bool XCCalendarDayEntry::SetShowAccountStatus(bool statusInput){
371         
372         showAccount = statusInput;
373         
376 bool XCCalendarDayEntry::SetShowCalendarStatus(bool statusInput){
378         showCalendar = statusInput;
379         
382 bool XCCalendarDayEntry::GetShowAccountStatus(){
383         
384         return showAccount;
385         
388 bool XCCalendarDayEntry::GetShowCalendarStatus(){
390         return showCalendar;
391         
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