Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Add files for Win32 support
[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 wxDEFINE_EVENT(XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEvent);
24 wxDEFINE_EVENT(XCCALENDARMONTH_HIDEACCOUNTENTRIES, wxCommandEvent);
25 wxDEFINE_EVENT(XCCALENDARMONTH_SHOWACCOUNTENTRIES, wxCommandEvent);
26 wxDEFINE_EVENT(XCCALENDARMONTH_HIDECALENDARENTRIES, wxCommandEvent);
27 wxDEFINE_EVENT(XCCALENDARMONTH_SHOWCALENDARENTRIES, wxCommandEvent);
28 wxDEFINE_EVENT(XCCALENDARMONTH_DELETECALENDARENTRIES, wxCommandEvent);
29 wxDEFINE_EVENT(XCCALENDARMONTH_DISPLAYEVENTMENU, wxCommandEvent);
30 wxDEFINE_EVENT(XCCALENDARMONTH_DELETEENTRY, wxCommandEvent);
31 wxDEFINE_EVENT(XCCALENDARMONTH_ADDENTRY, wxCommandEvent);
32 wxDEFINE_EVENT(XCCALENDARMONTH_UPDATEENTRY, wxCommandEvent);
33 wxDEFINE_EVENT(XCCALENDARMONTH_UPDATECALENDARCOLOUR, wxCommandEvent);
35 BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
36 END_EVENT_TABLE()
38 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)
39         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL){
40         calendarStorage = dataStorage;
41                 
42         mondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
43         tuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
44         wednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
45         thursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
46         fridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
47         saturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
48         sundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
49                 
50         eventMenu = new XCEventMenu;
51         
52         windowSizer->Add(mondayText, 1, wxEXPAND|wxALL, 0);
53         windowSizer->Add(tuesdayText, 1, wxEXPAND|wxALL, 0);
54         windowSizer->Add(wednesdayText, 1, wxEXPAND|wxALL, 0);
55         windowSizer->Add(thursdayText, 1, wxEXPAND|wxALL, 0);
56         windowSizer->Add(fridayText, 1, wxEXPAND|wxALL, 0);
57         windowSizer->Add(saturdayText, 1, wxEXPAND|wxALL, 0);   
58         windowSizer->Add(sundayText, 1, wxEXPAND|wxALL, 0);
59         
60         ProcessGrid(grid, hideAccounts, hideCalendars);
61         
62         // Setup the days.
63         
64         // Setup the growable rows and columns.
65         
66         windowSizer->AddGrowableCol(0);
67         windowSizer->AddGrowableCol(1);
68         windowSizer->AddGrowableCol(2);
69         windowSizer->AddGrowableCol(3);
70         windowSizer->AddGrowableCol(4);
71         windowSizer->AddGrowableCol(5); 
72         windowSizer->AddGrowableCol(6);
73         windowSizer->SetFlexibleDirection( wxBOTH );
74         windowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
75         
76         this->SetSizer(windowSizer);
77         windowSizer->Fit(this);
78         this->Layout();
79         this->SetBackgroundColour(wxColour(0,0,0));
80         
81         // Bind events to the control.
83         Bind(XCCALENDARMONTH_DESELECTOTHERENTRIES, &XCCalendarMonthView::DeselectOthersEvent, this, ID_MONTHVIEWCLEARSELECTION);
84         Bind(XCCALENDARMONTH_HIDEACCOUNTENTRIES, &XCCalendarMonthView::HideAccountEntries, this, ID_HIDEENTRIES);
85         Bind(XCCALENDARMONTH_SHOWACCOUNTENTRIES, &XCCalendarMonthView::ShowAccountEntries, this, ID_SHOWENTRIES);
86         Bind(XCCALENDARMONTH_HIDECALENDARENTRIES, &XCCalendarMonthView::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
87         Bind(XCCALENDARMONTH_SHOWCALENDARENTRIES, &XCCalendarMonthView::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
88         Bind(XCCALENDARMONTH_DELETECALENDARENTRIES, &XCCalendarMonthView::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
89         Bind(XCCALENDARMONTH_DISPLAYEVENTMENU, &XCCalendarMonthView::ShowEventMenu, this, ID_DISPLAYEVENTMENU);
90         Bind(XCCALENDARMONTH_DELETEENTRY, &XCCalendarMonthView::DeleteCalendarEntry, this, ID_DELETEENTRY);
91         Bind(XCCALENDARMONTH_ADDENTRY, &XCCalendarMonthView::AddCalendarEntry, this, ID_ADDENTRY);
92         Bind(XCCALENDARMONTH_UPDATEENTRY, &XCCalendarMonthView::UpdateCalendarEntry, this, ID_UPDATEENTRY);
93         Bind(XCCALENDARMONTH_UPDATECALENDARCOLOUR, &XCCalendarMonthView::UpdateCalendarColour, this, ID_UPDATECOLOUR);
94         
95 }
97 XCCalendarMonthView::~XCCalendarMonthView(){
98         
99         delete mondayText;
100         delete tuesdayText;
101         delete wednesdayText;
102         delete thursdayText;
103         delete fridayText;
104         delete saturdayText;
105         delete sundayText;
106         
107         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
108                 dayIter != calendarDayList.end(); dayIter++){
109                         
110                 delete ((*dayIter));
111                         
112         }
113         
114         delete eventMenu;
115         this->SetSizer(nullptr, true);
116         
117         // Unbind events from control
118         
119         Unbind(XCCALENDARMONTH_DESELECTOTHERENTRIES, &XCCalendarMonthView::DeselectOthersEvent, this);
120         Unbind(XCCALENDARMONTH_HIDEACCOUNTENTRIES, &XCCalendarMonthView::HideAccountEntries, this);
121         Unbind(XCCALENDARMONTH_SHOWACCOUNTENTRIES, &XCCalendarMonthView::ShowAccountEntries, this);
122         Unbind(XCCALENDARMONTH_HIDECALENDARENTRIES, &XCCalendarMonthView::HideCalendarEntries, this);
123         Unbind(XCCALENDARMONTH_SHOWCALENDARENTRIES, &XCCalendarMonthView::ShowCalendarEntries, this);
124         Unbind(XCCALENDARMONTH_DELETECALENDARENTRIES, &XCCalendarMonthView::DeleteCalendarEntries, this);
125         Unbind(XCCALENDARMONTH_DISPLAYEVENTMENU, &XCCalendarMonthView::ShowEventMenu, this);
126         Unbind(XCCALENDARMONTH_DELETEENTRY, &XCCalendarMonthView::DeleteCalendarEntry, this);
127         Unbind(XCCALENDARMONTH_ADDENTRY, &XCCalendarMonthView::AddCalendarEntry, this);
128         Unbind(XCCALENDARMONTH_UPDATEENTRY, &XCCalendarMonthView::UpdateCalendarEntry, this);
129         Unbind(XCCALENDARMONTH_UPDATECALENDARCOLOUR, &XCCalendarMonthView::UpdateCalendarColour, this);
130         
131         // Don't delete CalendarDataStorage object (used elsewhere).
132         
133         calendarStorage = nullptr;
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(100,100));
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::ResizeFrameEvent(wxSizeEvent &SizeEvent){
180         // TODO: Check if window size is less than 120 pixels and if it is,
181         // switch to the small block mode.
182         
183         // Refresh the window.
184         
185         this->Refresh();
186         
189 void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &deselectEvent){
190         
191         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
192                 dayIter != calendarDayList.end(); dayIter++){
193                         
194                 if (deselectEvent.GetClientData() != (void*)(*dayIter)){
195                         
196                         wxCommandEvent deselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
197                         deselectEvent.SetId(ID_DESELECTALLITEMS);
198                         wxPostEvent((*dayIter), deselectEvent);
199                         
200                 }
201                         
202         }
203         
206 void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
207         
208         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
209                 dayIter != calendarDayList.end(); dayIter++){
210                         
211                 wxCommandEvent hideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
212                 hideEvent.SetInt(accountData.GetInt());
213                 hideEvent.SetId(ID_HIDEENTRIES);
214                 wxPostEvent((*dayIter), hideEvent);
215                         
216         }
217         
220 void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
221         
222         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
223                 dayIter != calendarDayList.end(); dayIter++){
224                         
225                 wxCommandEvent showEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
226                 showEvent.SetInt(accountData.GetInt());
227                 showEvent.SetId(ID_SHOWENTRIES);
228                 wxPostEvent((*dayIter), showEvent);
229                         
230         }
231         
234 void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
235         
236         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
237                 dayIter != calendarDayList.end(); dayIter++){
238                         
239                 wxCommandEvent hideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
240                 hideEvent.SetInt(accountData.GetInt());
241                 hideEvent.SetId(ID_HIDECALENDARENTRIES);
242                 wxPostEvent((*dayIter), hideEvent);
243                         
244         }
245         
248 void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
249         
250         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
251                 dayIter != calendarDayList.end(); dayIter++){
252                         
253                 wxCommandEvent hideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
254                 hideEvent.SetInt(accountData.GetInt());
255                 hideEvent.SetId(ID_SHOWCALENDARENTRIES);
256                 wxPostEvent((*dayIter), hideEvent);
257                         
258         }
259         
262 void XCCalendarMonthView::DeleteCalendarEntries(wxCommandEvent &calendarData){
263         
264         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
265                 dayIter != calendarDayList.end(); dayIter++){
267                 wxCommandEvent deleteEvent(XCCALENDARDAY_DELETECALENDARENTRIES);
268                 deleteEvent.SetInt(calendarData.GetInt());
269                 deleteEvent.SetId(ID_DELETECALENDARENTRIES);
270                 wxPostEvent((*dayIter), deleteEvent);
271                         
272         }
273         
276 void XCCalendarMonthView::DeleteCalendarEntry(wxCommandEvent &eventData){
277         
278         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
279                 dayIter != calendarDayList.end(); dayIter++){
281                 wxCommandEvent deleteEvent(XCCALENDARDAY_DELETEENTRY);
282                 deleteEvent.SetInt(eventData.GetInt());
283                 deleteEvent.SetId(ID_DELETEENTRY);
284                 wxPostEvent((*dayIter), deleteEvent);
285                         
286         }       
287         
290 void XCCalendarMonthView::AddCalendarEntry(wxCommandEvent &eventData){
291         
292         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
293         bool foundDate = false;
294         
295         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
296                 dayIter != calendarDayList.end(); dayIter++){
297                         
298                 // Check if the date matches with the date in the day
299                 // widget. If it does, add the widget.
300                         
301                 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
302                         (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
303                         (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
304                         
305                         wxCommandEvent addEvent(XCCALENDARDAY_ADDENTRY);
306                         addEvent.SetId(ID_ADDENTRY);
307                         addEvent.SetClientData(eventInfo);
308                         wxPostEvent((*dayIter), addEvent);
309                         foundDate = true;
310                         break;
311                         
312                 }
313                         
314         }
315         
316         if (foundDate == false){
317                 
318                 delete eventInfo;
319                 eventInfo = nullptr;
320                 
321         }
322         
325 void XCCalendarMonthView::UpdateCalendarEntry(wxCommandEvent &eventData){
326         
327         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
328         bool foundDate = false;
329         
330         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
331                 dayIter != calendarDayList.end(); dayIter++){
332         
333                 wxCommandEvent addEvent(XCCALENDARDAY_DELETEENTRY);
334                 addEvent.SetId(ID_DELETEENTRY);
335                 addEvent.SetInt(eventInfo->eventID);
336                 wxPostEvent((*dayIter), addEvent);
337                         
338         }
339         
340         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
341                 dayIter != calendarDayList.end(); dayIter++){
342                         
343                 // Check if the date matches with the date in the day
344                 // widget. If it does, update the widget.
345                         
346                 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
347                         (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
348                         (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
349                         
350                         wxCommandEvent addEvent(XCCALENDARDAY_ADDENTRY);
351                         addEvent.SetId(ID_ADDENTRY);
352                         addEvent.SetClientData(eventInfo);
353                         wxPostEvent((*dayIter), addEvent);
354                         foundDate = true;
355                         break;
356                         
357                 }
358                         
359         }
360         
361         if (foundDate == false){
362                 
363                 delete eventInfo;
364                 eventInfo = nullptr;
365                 
366         }
367         
370 void XCCalendarMonthView::UpdateCalendarColour(wxCommandEvent &colourData){
371         
372         ColourUpdateProperties *colourDataInfo = (ColourUpdateProperties*)colourData.GetClientData();
373         
374         for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
375                 dayIter != calendarDayList.end(); dayIter++){
376                         
377                 // Check if the date matches with the date in the day
378                 // widget. If it does, update the widget.
380                 ColourUpdateProperties *colourDataPassInfo = colourDataInfo;
381                         
382                 wxCommandEvent updateColour(XCCALENDARDAY_UPDATECALENDARCOLOUR);
383                 updateColour.SetId(ID_UPDATECOLOUR);
384                 updateColour.SetClientData(colourDataPassInfo);
385                 wxPostEvent((*dayIter), updateColour);
386                         
387         }
388         
391 void XCCalendarMonthView::ShowEventMenu(wxCommandEvent &eventData){
392         
393         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
394         
395         eventMenu->SetEventID(eventInfo->eventID);
396         eventMenu->SetCalendarID(eventInfo->calendarID);
397         eventMenu->SetWindowPointer(this->GetParent()->GetParent());
398         
399         this->PopupMenu(eventMenu, wxDefaultPosition);
400         
401         delete eventInfo;
402         eventInfo = nullptr;
403         
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