Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Widget controls updated
[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