Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
e5c384f81f0425a012e528594c3bcf295243e875
[xestiacalendar/.git] / source / widgets / XCCalendarMonthView.cpp
1 // XCCalendarMonthView.cpp - Xestia Calendar XCCalendarMonthView 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 "XCCalendarMonthView.h"
21 using namespace std;
23 BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
24 EVT_PAINT(XCCalendarMonthView::PaintFrameEvent)
25 END_EVENT_TABLE()
27 XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
28         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL){
29         
30         calendarStorage = dataStorage;
31                 
32         mondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
33         tuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
34         wednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
35         thursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
36         fridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
37         saturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
38         sundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
39                 
40         eventMenu = new XCEventMenu;
41         
42         WindowSizer->Add(mondayText, 1, wxEXPAND|wxALL, 0);
43         WindowSizer->Add(tuesdayText, 1, wxEXPAND|wxALL, 0);
44         WindowSizer->Add(wednesdayText, 1, wxEXPAND|wxALL, 0);
45         WindowSizer->Add(thursdayText, 1, wxEXPAND|wxALL, 0);
46         WindowSizer->Add(fridayText, 1, wxEXPAND|wxALL, 0);
47         WindowSizer->Add(saturdayText, 1, wxEXPAND|wxALL, 0);   
48         WindowSizer->Add(sundayText, 1, wxEXPAND|wxALL, 0);
49         
50         ProcessGrid(grid, hideAccounts, hideCalendars);
51         
52         // Setup the days.
53         
54         // Setup the growable rows and columns.
55         
56         windowSizer->AddGrowableCol(0);
57         windowSizer->AddGrowableCol(1);
58         windowSizer->AddGrowableCol(2);
59         windowSizer->AddGrowableCol(3);
60         windowSizer->AddGrowableCol(4);
61         windowSizer->AddGrowableCol(5); 
62         windowSizer->AddGrowableCol(6);
63         windowSizer->SetFlexibleDirection( wxBOTH );
64         windowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
65         
66         this->SetSizer(windowSizer);
67         windowSizer->Fit(this);
68         this->Layout();
69         this->SetBackgroundColour(wxColour(0,0,0));
70         
71         Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
72         Connect(ID_HIDEENTRIES, XCCALENDARMONTH_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideAccountEntries));
73         Connect(ID_SHOWENTRIES, XCCALENDARMONTH_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowAccountEntries));
74         Connect(ID_HIDECALENDARENTRIES, XCCALENDARMONTH_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideCalendarEntries));
75         Connect(ID_SHOWCALENDARENTRIES, XCCALENDARMONTH_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowCalendarEntries));
76         Connect(ID_DELETECALENDARENTRIES, XCCALENDARMONTH_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeleteCalendarEntries));
77         Connect(ID_DISPLAYEVENTMENU, XCCALENDARMONTH_DISPLAYEVENTMENU, wxCommandEventHandler(XCCalendarMonthView::ShowEventMenu));
78         Connect(ID_DELETEENTRY, XCCALENDARMONTH_DELETEENTRY, wxCommandEventHandler(XCCalendarMonthView::DeleteCalendarEntry));
79         Connect(ID_ADDENTRY, XCCALENDARMONTH_ADDENTRY, wxCommandEventHandler(XCCalendarMonthView::AddCalendarEntry));
80         Connect(ID_UPDATEENTRY, XCCALENDARMONTH_UPDATEENTRY, wxCommandEventHandler(XCCalendarMonthView::UpdateCalendarEntry));
81         Connect(ID_UPDATECOLOUR, XCCALENDARMONTH_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarMonthView::UpdateCalendarColour));
83 }
85 XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
86         : wxPanel(NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){
87         
88         Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
89         
90         calendarStorage = dataStorage;
91                 
92         mondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
93         tuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
94         wednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
95         thursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
96         fridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
97         saturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
98         sundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
99         
100         windowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0);
101         windowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0);
102         windowSizer->Add(WednesdayText, 1, wxEXPAND|wxALL, 0);
103         windowSizer->Add(ThursdayText, 1, wxEXPAND|wxALL, 0);
104         windowSizer->Add(FridayText, 1, wxEXPAND|wxALL, 0);
105         windowSizer->Add(SaturdayText, 1, wxEXPAND|wxALL, 0);   
106         windowSizer->Add(SundayText, 1, wxEXPAND|wxALL, 0);
107         
108         ProcessGrid(grid, hideAccounts, hideCalendars);
109         
110         // Setup the days.
111         
112         // Setup the growable rows and columns.
113         
114         windowSizer->AddGrowableCol(0);
115         windowSizer->AddGrowableCol(1);
116         windowSizer->AddGrowableCol(2);
117         windowSizer->AddGrowableCol(3);
118         windowSizer->AddGrowableCol(4);
119         windowSizer->AddGrowableCol(5); 
120         windowSizer->AddGrowableCol(6);
121         windowSizer->SetFlexibleDirection( wxBOTH );
122         windowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
123         
124         this->SetSizer(windowSizer);
125         windowSizer->Fit(this);
126         this->Layout();
127         this->SetBackgroundColour(wxColour(0,0,0));
128         
131 XCCalendarMonthView::~XCCalendarMonthView(){
132         
133         
134         
137 void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars){
138         
139         // TODO: Delete the old calendar entries.
140         
141         // Add the new calendar entries.
142         
143         int week = 0;
144         
145         for (vector<XCCalendarMonthViewGridDayWeek>::iterator weekIter = grid->weekList.begin();
146                 weekIter != grid->weekList.end(); weekIter++){
147                         
148                 week++;
149                         
150                 for (vector<XCCalendarMonthViewGridDayData>::iterator dayIter = (*weekIter).dayList.begin();
151                         dayIter != (*weekIter).dayList.end(); DayIter++){
152                                 
153                         // Add Calendar entries.
154                                 
155                         XCCalendarDay *calendarDayItem = new XCCalendarDay(this, "XCCalendarMonthView Test", wxPoint(50, 50), wxSize(200, 200));
156                                 
157                         // Setup the control.
158                                 
159                         calendarDayItem->SetupControl((*dayIter).day, (*dayIter).month, (*dayIter).year, (*dayIter).isInMonth, this, calendarStorage, hideAccounts, hideCalendars);
160                                 
161                         calendarDayList.push_back(calendarDayItem);
162                         windowSizer->Add(calendarDayItem, 1, wxEXPAND, 5);
163                                 
164                 }
165                         
166         }
167         
168         // Add the Growable Rows.
169         
170         for (int weekSeek = 0; weekSeek < week; weekSeek++){
171                 
172                 windowSizer->AddGrowableRow((weekSeek + 1));
173                 
174         }
175         
178 void XCCalendarMonthView::Repaint(){
179         
180         // Draw the border.
181         
182         this->Layout();
186 void XCCalendarMonthView::PaintFrameEvent(wxPaintEvent &PaintEvent){
188         Repaint();
189         
192 void XCCalendarMonthView::ResizeFrameEvent(wxSizeEvent &SizeEvent){
194         // TODO: Check if window size is less than 120 pixels and if it is,
195         // switch to the small block mode.
196         
197         // Refresh the window.
198         
199         this->Refresh();
200         
203 void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &DeselectEvent){
204         
205         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
206                 dayIter != calendarDayList.end(); DayIter++){
207                         
208                 if (deselectEvent.GetClientData() != (void*)(*dayIter)){
209                         
210                         wxCommandEvent deselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
211                         deselectEvent.SetId(ID_DESELECTALLITEMS);
212                         wxPostEvent((*dayIter), deselectEvent);
213                         
214                 }
215                         
216         }
217         
220 void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
221         
222         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
223                 dayIter != calendarDayList.end(); dayIter++){
224                         
225                 wxCommandEvent hideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
226                 hideEvent.SetInt(accountData.GetInt());
227                 hideEvent.SetId(ID_HIDEENTRIES);
228                 wxPostEvent((*dayIter), hideEvent);
229                         
230         }
231         
234 void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
235         
236         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
237                 dayIter != calendarDayList.end(); dayIter++){
238                         
239                 wxCommandEvent showEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
240                 showEvent.SetInt(accountData.GetInt());
241                 showEvent.SetId(ID_SHOWENTRIES);
242                 wxPostEvent((*dayIter), showEvent);
243                         
244         }
245         
248 void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
249         
250         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
251                 dayIter != calendarDayList.end(); dayIter++){
252                         
253                 wxCommandEvent hideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
254                 hideEvent.SetInt(accountData.GetInt());
255                 hideEvent.SetId(ID_HIDECALENDARENTRIES);
256                 wxPostEvent((*dayIter), hideEvent);
257                         
258         }
259         
262 void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
263         
264         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
265                 dayIter != calendarDayList.end(); dayIter++){
266                         
267                 wxCommandEvent hideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
268                 hideEvent.SetInt(accountData.GetInt());
269                 hideEvent.SetId(ID_SHOWCALENDARENTRIES);
270                 wxPostEvent((*dayIter), hideEvent);
271                         
272         }
273         
276 void XCCalendarMonthView::DeleteCalendarEntries(wxCommandEvent &calendarData){
277         
278         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
279                 dayIter != calendarDayList.end(); dayIter++){
281                 wxCommandEvent deleteEvent(XCCALENDARDAY_DELETECALENDARENTRIES);
282                 deleteEvent.SetInt(calendarData.GetInt());
283                 deleteEvent.SetId(ID_DELETECALENDARENTRIES);
284                 wxPostEvent((*dayIter), deleteEvent);
285                         
286         }
287         
290 void XCCalendarMonthView::DeleteCalendarEntry(wxCommandEvent &eventData){
291         
292         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
293                 dayIter != calendarDayList.end(); dayIter++){
295                 wxCommandEvent deleteEvent(XCCALENDARDAY_DELETEENTRY);
296                 deleteEvent.SetInt(eventData.GetInt());
297                 deleteEvent.SetId(ID_DELETEENTRY);
298                 wxPostEvent((*dayIter), deleteEvent);
299                         
300         }       
301         
304 void XCCalendarMonthView::AddCalendarEntry(wxCommandEvent &eventData){
305         
306         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
307         bool foundDate = false;
308         
309         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
310                 dayIter != calendarDayList.end(); dayIter++){
311                         
312                 // Check if the date matches with the date in the day
313                 // widget. If it does, add the widget.
314                         
315                 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
316                         (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
317                         (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
318                         
319                         wxCommandEvent addEvent(XCCALENDARDAY_ADDENTRY);
320                         addEvent.SetId(ID_ADDENTRY);
321                         addEvent.SetClientData(eventInfo);
322                         wxPostEvent((*dayIter), addEvent);
323                         foundDate = true;
324                         break;
325                         
326                 }
327                         
328         }
329         
330         if (foundDate == false){
331                 
332                 delete eventInfo;
333                 eventInfo = nullptr;
334                 
335         }
336         
339 void XCCalendarMonthView::UpdateCalendarEntry(wxCommandEvent &eventData){
340         
341         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
342         bool foundDate = false;
343         
344         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
345                 dayIter != calendarDayList.end(); dayIter++){
346                         
347                 // Check if the date matches with the date in the day
348                 // widget. If it does, update the widget.
349                         
350                 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
351                         (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
352                         (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
353                         
354                         wxCommandEvent addEvent(XCCALENDARDAY_UPDATEENTRY);
355                         addEvent.SetId(ID_UPDATEENTRY);
356                         addEvent.SetClientData(eventInfo);
357                         wxPostEvent((*dayIter), addEvent);
358                         foundDate = true;
359                         break;
360                         
361                 }
362                         
363         }
364         
365         if (foundDate == false){
366                 
367                 delete eventInfo;
368                 eventInfo = nullptr;
369                 
370         }
371         
374 void XCCalendarMonthView::UpdateCalendarColour(wxCommandEvent &colourData){
375         
376         ColourUpdateProperties *colourDataInfo = (ColourUpdateProperties*)colourData.GetClientData();
377         
378         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
379                 dayIter != calendarDayList.end(); dayIter++){
380                         
381                 // Check if the date matches with the date in the day
382                 // widget. If it does, update the widget.
384                 ColourUpdateProperties *colourDataPassInfo = colourDataInfo;
385                         
386                 wxCommandEvent updateColour(XCCALENDARDAY_UPDATECALENDARCOLOUR);
387                 updateColour.SetId(ID_UPDATECOLOUR);
388                 updateColour.SetClientData(colourDataPassInfo);
389                 wxPostEvent((*dayIter), updateColour);
390                         
391         }
392         
395 void XCCalendarMonthView::ShowEventMenu(wxCommandEvent &eventData){
396         
397         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
398         
399         eventMenu->SetEventID(eventInfo->eventID);
400         eventMenu->SetCalendarID(eventInfo->calendarID);
401         eventMenu->SetWindowPointer(this->GetParent()->GetParent());
402         
403         this->PopupMenu(eventMenu, wxDefaultPosition);
404         
405         delete eventInfo;
406         eventInfo = nullptr;
407         
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