1 // XCCalendarCtrl.cpp - Xestia Calendar XCCalendarCtrl 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 "XCCalendarCtrl.h"
21 BEGIN_EVENT_TABLE(XCCalendarCtrl, wxPanel)
26 XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorage)
27 : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize){
29 // Setup the pointers.
31 calendarStorage = dataStorage;
33 // Setup the main sizer.
35 szrMain = new wxFlexGridSizer(2, 1, 0, 0);
36 szrMain->AddGrowableCol(0);
37 szrMain->AddGrowableRow(1);
38 szrMain->SetFlexibleDirection(wxBOTH);
39 szrMain->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
40 this->SetSizer(szrMain);
42 // Setup the top menu.
44 ManipulatorCtrl = new XCCalendarManipulator(this, "XCCalendarManipulator Test", wxDefaultPosition, wxDefaultSize, calendarStorage);
46 // Setup the month view grid.
48 wxDateTime DTNow = wxDateTime::Now();
49 int currentMonth = ((int)DTNow.GetMonth() + 1);
50 int currentYear = DTNow.GetYear();
52 XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear);
53 szrMain->Add(ManipulatorCtrl, 1, wxEXPAND, 5);
55 // Get the list of hidden accounts and calendars.
57 vector<int> hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
58 vector<int> hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
60 MonthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
61 szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
63 // Connect events to the control.
65 Connect(ID_CHANGEGRID, XCCALENDARCTRL_CHANGEGRID, wxCommandEventHandler(XCCalendarCtrl::UpdateGrid));
66 Connect(ID_HIDEENTRIES, XCCALENDARCTRL_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarCtrl::HideAccountEntries));
67 Connect(ID_SHOWENTRIES, XCCALENDARCTRL_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowAccountEntries));
68 Connect(ID_HIDECALENDARENTRIES, XCCALENDARCTRL_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::HideCalendarEntries));
69 Connect(ID_SHOWCALENDARENTRIES, XCCALENDARCTRL_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowCalendarEntries));
70 Connect(ID_DELETECALENDARENTRIES, XCCALENDARCTRL_DELETECALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::DeleteCalendarEntries));
71 Connect(ID_DELETEENTRY, XCCALENDARCTRL_DELETEENTRY, wxCommandEventHandler(XCCalendarCtrl::DeleteCalendarEntry));
72 Connect(ID_ADDENTRY, XCCALENDARCTRL_ADDENTRY, wxCommandEventHandler(XCCalendarCtrl::AddCalendarEntry));
73 Connect(ID_UPDATEENTRY, XCCALENDARCTRL_UPDATEENTRY, wxCommandEventHandler(XCCalendarCtrl::UpdateCalendarEntry));
74 Connect(ID_UPDATECOLOUR, XCCALENDARCTRL_UPDATECALENDARCOLOUR, wxCommandEventHandler(XCCalendarCtrl::UpdateCalendarColour));
78 XCCalendarCtrl::~XCCalendarCtrl(){
80 // Destory the controls in the XCCalendarCtrl class.
84 void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
86 XCCalendarMonthView *OldGrid = nullptr;
90 OldGrid = MonthViewCtrl;
92 // Get the list of hidden accounts and calendars.
94 vector<int> hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
95 vector<int> hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
99 XCCalendarMonthViewGrid NewGrid = GenerateMonthGrid(ManipulatorCtrl->GetMonth(), ManipulatorCtrl->GetYear());
100 MonthViewCtrl = new XCCalendarMonthView(this, _(""), wxDefaultPosition, wxDefaultSize, &NewGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
102 // Detach the old grid and attach the new one.
105 OldGrid->Show(false);
106 szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
109 // Delete the old grid.
116 void XCCalendarCtrl::HideAccountEntries(wxCommandEvent &accountData){
118 // Get the list of calendar IDs for the account and go through
119 // the list of entries in each day control.
121 wxCommandEvent event(XCCALENDARMONTH_HIDEACCOUNTENTRIES);
122 event.SetInt(accountData.GetInt());
123 event.SetId(ID_HIDEENTRIES);
124 wxPostEvent(MonthViewCtrl, event);
128 void XCCalendarCtrl::ShowAccountEntries(wxCommandEvent &accountData){
130 // Get the list of calendar IDs for the account and go through
131 // the list of entries in each day control.
133 wxCommandEvent event(XCCALENDARMONTH_SHOWACCOUNTENTRIES);
134 event.SetInt(accountData.GetInt());
135 event.SetId(ID_SHOWENTRIES);
136 wxPostEvent(MonthViewCtrl, event);
140 void XCCalendarCtrl::HideCalendarEntries(wxCommandEvent &calendarData){
142 // Get the list of calendar IDs for the account and go through
143 // the list of entries in each day control.
145 wxCommandEvent event(XCCALENDARMONTH_HIDECALENDARENTRIES);
146 event.SetInt(calendarData.GetInt());
147 event.SetId(ID_HIDECALENDARENTRIES);
148 wxPostEvent(MonthViewCtrl, event);
152 void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){
154 // Get the list of calendar IDs for the account and go through
155 // the list of entries in each day control.
157 wxCommandEvent event(XCCALENDARMONTH_SHOWCALENDARENTRIES);
158 event.SetInt(calendarData.GetInt());
159 event.SetId(ID_SHOWCALENDARENTRIES);
160 wxPostEvent(MonthViewCtrl, event);
164 void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){
166 wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES);
167 event.SetInt(calendarData.GetInt());
168 event.SetId(ID_DELETECALENDARENTRIES);
169 wxPostEvent(MonthViewCtrl, event);
173 void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){
175 wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY);
176 event.SetInt(eventData.GetInt());
177 event.SetId(ID_DELETEENTRY);
178 wxPostEvent(MonthViewCtrl, event);
182 void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){
184 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
186 eventInfo->hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
187 eventInfo->hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
189 wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY);
190 addEvent.SetId(ID_ADDENTRY);
191 addEvent.SetClientData(eventInfo);
192 wxPostEvent(MonthViewCtrl, addEvent);
196 void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){
198 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
200 wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY);
201 addEvent.SetId(ID_UPDATEENTRY);
202 addEvent.SetClientData(eventInfo);
203 wxPostEvent(MonthViewCtrl, addEvent);
207 void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){
209 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
211 wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR);
212 colourEvent.SetId(ID_UPDATECOLOUR);
213 colourEvent.SetClientData(colourInfo);
214 wxPostEvent(MonthViewCtrl, colourEvent);