1 // XCCalendarMonthView.cpp - Xestia Calendar XCCalendarMonthView widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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"
23 BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
24 EVT_PAINT(XCCalendarMonthView::PaintFrameEvent)
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){
30 calendarStorage = dataStorage;
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);
40 eventMenu = new XCEventMenu;
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);
50 ProcessGrid(grid, hideAccounts, hideCalendars);
54 // Setup the growable rows and columns.
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 );
66 this->SetSizer(windowSizer);
67 windowSizer->Fit(this);
69 this->SetBackgroundColour(wxColour(0,0,0));
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));
85 XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
86 : wxPanel(NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){
88 Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
90 calendarStorage = dataStorage;
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);
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);
108 ProcessGrid(grid, hideAccounts, hideCalendars);
112 // Setup the growable rows and columns.
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 );
124 this->SetSizer(windowSizer);
125 windowSizer->Fit(this);
127 this->SetBackgroundColour(wxColour(0,0,0));
131 XCCalendarMonthView::~XCCalendarMonthView(){
137 void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars){
139 // TODO: Delete the old calendar entries.
141 // Add the new calendar entries.
145 for (vector<XCCalendarMonthViewGridDayWeek>::iterator weekIter = grid->weekList.begin();
146 weekIter != grid->weekList.end(); weekIter++){
150 for (vector<XCCalendarMonthViewGridDayData>::iterator dayIter = (*weekIter).dayList.begin();
151 dayIter != (*weekIter).dayList.end(); DayIter++){
153 // Add Calendar entries.
155 XCCalendarDay *calendarDayItem = new XCCalendarDay(this, "XCCalendarMonthView Test", wxPoint(50, 50), wxSize(200, 200));
157 // Setup the control.
159 calendarDayItem->SetupControl((*dayIter).day, (*dayIter).month, (*dayIter).year, (*dayIter).isInMonth, this, calendarStorage, hideAccounts, hideCalendars);
161 calendarDayList.push_back(calendarDayItem);
162 windowSizer->Add(calendarDayItem, 1, wxEXPAND, 5);
168 // Add the Growable Rows.
170 for (int weekSeek = 0; weekSeek < week; weekSeek++){
172 windowSizer->AddGrowableRow((weekSeek + 1));
178 void XCCalendarMonthView::Repaint(){
186 void XCCalendarMonthView::PaintFrameEvent(wxPaintEvent &PaintEvent){
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.
197 // Refresh the window.
203 void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &DeselectEvent){
205 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
206 dayIter != calendarDayList.end(); DayIter++){
208 if (deselectEvent.GetClientData() != (void*)(*dayIter)){
210 wxCommandEvent deselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
211 deselectEvent.SetId(ID_DESELECTALLITEMS);
212 wxPostEvent((*dayIter), deselectEvent);
220 void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
222 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
223 dayIter != calendarDayList.end(); dayIter++){
225 wxCommandEvent hideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
226 hideEvent.SetInt(accountData.GetInt());
227 hideEvent.SetId(ID_HIDEENTRIES);
228 wxPostEvent((*dayIter), hideEvent);
234 void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
236 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
237 dayIter != calendarDayList.end(); dayIter++){
239 wxCommandEvent showEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
240 showEvent.SetInt(accountData.GetInt());
241 showEvent.SetId(ID_SHOWENTRIES);
242 wxPostEvent((*dayIter), showEvent);
248 void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
250 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
251 dayIter != calendarDayList.end(); dayIter++){
253 wxCommandEvent hideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
254 hideEvent.SetInt(accountData.GetInt());
255 hideEvent.SetId(ID_HIDECALENDARENTRIES);
256 wxPostEvent((*dayIter), hideEvent);
262 void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
264 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
265 dayIter != calendarDayList.end(); dayIter++){
267 wxCommandEvent hideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
268 hideEvent.SetInt(accountData.GetInt());
269 hideEvent.SetId(ID_SHOWCALENDARENTRIES);
270 wxPostEvent((*dayIter), hideEvent);
276 void XCCalendarMonthView::DeleteCalendarEntries(wxCommandEvent &calendarData){
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);
290 void XCCalendarMonthView::DeleteCalendarEntry(wxCommandEvent &eventData){
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);
304 void XCCalendarMonthView::AddCalendarEntry(wxCommandEvent &eventData){
306 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
307 bool foundDate = false;
309 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
310 dayIter != calendarDayList.end(); dayIter++){
312 // Check if the date matches with the date in the day
313 // widget. If it does, add the widget.
315 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
316 (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
317 (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
319 wxCommandEvent addEvent(XCCALENDARDAY_ADDENTRY);
320 addEvent.SetId(ID_ADDENTRY);
321 addEvent.SetClientData(eventInfo);
322 wxPostEvent((*dayIter), addEvent);
330 if (foundDate == false){
339 void XCCalendarMonthView::UpdateCalendarEntry(wxCommandEvent &eventData){
341 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
342 bool foundDate = false;
344 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
345 dayIter != calendarDayList.end(); dayIter++){
347 // Check if the date matches with the date in the day
348 // widget. If it does, update the widget.
350 if ((*dayIter)->GetCalendarYear() == eventInfo->eventYear &&
351 (*dayIter)->GetCalendarMonth() == (eventInfo->eventMonth + 1) &&
352 (*dayIter)->GetCalendarDay() == eventInfo->eventDay){
354 wxCommandEvent addEvent(XCCALENDARDAY_UPDATEENTRY);
355 addEvent.SetId(ID_UPDATEENTRY);
356 addEvent.SetClientData(eventInfo);
357 wxPostEvent((*dayIter), addEvent);
365 if (foundDate == false){
374 void XCCalendarMonthView::UpdateCalendarColour(wxCommandEvent &colourData){
376 ColourUpdateProperties *colourDataInfo = (ColourUpdateProperties*)colourData.GetClientData();
378 for (vector<XCCalendarDay*>::iterator dayIter = calendarDayList.begin();
379 dayIter != calendarDayList.end(); dayIter++){
381 // Check if the date matches with the date in the day
382 // widget. If it does, update the widget.
384 ColourUpdateProperties *colourDataPassInfo = colourDataInfo;
386 wxCommandEvent updateColour(XCCALENDARDAY_UPDATECALENDARCOLOUR);
387 updateColour.SetId(ID_UPDATECOLOUR);
388 updateColour.SetClientData(colourDataPassInfo);
389 wxPostEvent((*dayIter), updateColour);
395 void XCCalendarMonthView::ShowEventMenu(wxCommandEvent &eventData){
397 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
399 eventMenu->SetEventID(eventInfo->eventID);
400 eventMenu->SetCalendarID(eventInfo->calendarID);
401 eventMenu->SetWindowPointer(this->GetParent()->GetParent());
403 this->PopupMenu(eventMenu, wxDefaultPosition);