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 wxDEFINE_EVENT(XCCALENDARCTRL_CHANGEGRID, wxCommandEvent);
22 wxDEFINE_EVENT(XCCALENDARCTRL_HIDEACCOUNTENTRIES, wxCommandEvent);
23 wxDEFINE_EVENT(XCCALENDARCTRL_SHOWACCOUNTENTRIES, wxCommandEvent);
24 wxDEFINE_EVENT(XCCALENDARCTRL_HIDECALENDARENTRIES, wxCommandEvent);
25 wxDEFINE_EVENT(XCCALENDARCTRL_SHOWCALENDARENTRIES, wxCommandEvent);
26 wxDEFINE_EVENT(XCCALENDARCTRL_DELETECALENDARENTRIES, wxCommandEvent);
27 wxDEFINE_EVENT(XCCALENDARCTRL_ADDENTRY, wxCommandEvent);
28 wxDEFINE_EVENT(XCCALENDARCTRL_UPDATEENTRY, wxCommandEvent);
29 wxDEFINE_EVENT(XCCALENDARCTRL_UPDATECALENDARCOLOUR, wxCommandEvent);
30 wxDEFINE_EVENT(XCCALENDARCTRL_DELETEENTRY, wxCommandEvent);
34 XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorage)
35 : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize){
36 // Setup the pointers.
38 calendarStorage = dataStorage;
40 // Setup the main sizer.
42 szrMain = new wxFlexGridSizer(2, 1, 0, 0);
43 szrMain->AddGrowableCol(0);
44 szrMain->AddGrowableRow(1);
45 szrMain->SetFlexibleDirection(wxBOTH);
46 szrMain->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
47 this->SetSizer(szrMain);
49 // Setup the top menu.
51 manipulatorCtrl = new XCCalendarManipulator(this, "XCCalendarManipulator Test", wxDefaultPosition, wxDefaultSize, calendarStorage);
53 // Setup the month view grid.
55 wxDateTime dtNow = wxDateTime::Now();
56 int currentMonth = ((int)dtNow.GetMonth() + 1);
57 int currentYear = dtNow.GetYear();
59 XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear);
60 szrMain->Add(manipulatorCtrl, 1, wxEXPAND, 5);
62 // Get the list of hidden accounts and calendars.
64 vector<int> hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
65 vector<int> hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
67 monthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
68 szrMain->Add(monthViewCtrl, 1, wxEXPAND, 5);
70 // Bind events to the control.
72 Bind(XCCALENDARCTRL_CHANGEGRID, &XCCalendarCtrl::UpdateGrid, this, ID_CHANGEGRID);
73 Bind(XCCALENDARCTRL_HIDEACCOUNTENTRIES, &XCCalendarCtrl::HideAccountEntries, this, ID_HIDEENTRIES);
74 Bind(XCCALENDARCTRL_SHOWACCOUNTENTRIES, &XCCalendarCtrl::ShowAccountEntries, this, ID_SHOWENTRIES);
75 Bind(XCCALENDARCTRL_HIDECALENDARENTRIES, &XCCalendarCtrl::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
76 Bind(XCCALENDARCTRL_SHOWCALENDARENTRIES, &XCCalendarCtrl::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
77 Bind(XCCALENDARCTRL_DELETECALENDARENTRIES, &XCCalendarCtrl::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
78 Bind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
79 Bind(XCCALENDARCTRL_ADDENTRY, &XCCalendarCtrl::AddCalendarEntry, this, ID_ADDENTRY);
80 Bind(XCCALENDARCTRL_UPDATEENTRY, &XCCalendarCtrl::UpdateCalendarEntry, this, ID_UPDATEENTRY);
81 Bind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
82 Bind(XCCALENDARCTRL_UPDATECALENDARCOLOUR, &XCCalendarCtrl::UpdateCalendarColour, this, ID_UPDATECOLOUR);
85 XCCalendarCtrl::~XCCalendarCtrl(){
87 // Destory the controls in the XCCalendarCtrl class.
89 Unbind(XCCALENDARCTRL_CHANGEGRID, &XCCalendarCtrl::UpdateGrid, this, ID_CHANGEGRID);
90 Unbind(XCCALENDARCTRL_HIDEACCOUNTENTRIES, &XCCalendarCtrl::HideAccountEntries, this, ID_HIDEENTRIES);
91 Unbind(XCCALENDARCTRL_SHOWACCOUNTENTRIES, &XCCalendarCtrl::ShowAccountEntries, this, ID_SHOWENTRIES);
92 Unbind(XCCALENDARCTRL_HIDECALENDARENTRIES, &XCCalendarCtrl::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
93 Unbind(XCCALENDARCTRL_SHOWCALENDARENTRIES, &XCCalendarCtrl::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
94 Unbind(XCCALENDARCTRL_DELETECALENDARENTRIES, &XCCalendarCtrl::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
95 Unbind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
96 Unbind(XCCALENDARCTRL_ADDENTRY, &XCCalendarCtrl::AddCalendarEntry, this, ID_ADDENTRY);
97 Unbind(XCCALENDARCTRL_UPDATEENTRY, &XCCalendarCtrl::UpdateCalendarEntry, this, ID_UPDATEENTRY);
98 Unbind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
99 Unbind(XCCALENDARCTRL_UPDATECALENDARCOLOUR, &XCCalendarCtrl::UpdateCalendarColour, this, ID_UPDATECOLOUR);
103 delete monthViewCtrl;
104 monthViewCtrl = nullptr;
106 delete manipulatorCtrl;
107 manipulatorCtrl = nullptr;
109 calendarStorage = nullptr;
111 this->SetSizer(nullptr, true);
115 void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
117 XCCalendarMonthView *oldGrid = nullptr;
119 // Park the old grid.
121 oldGrid = monthViewCtrl;
123 // Get the list of hidden accounts and calendars.
125 vector<int> hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
126 vector<int> hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
128 // Create a new grid.
130 XCCalendarMonthViewGrid NewGrid = GenerateMonthGrid(manipulatorCtrl->GetMonth(), manipulatorCtrl->GetYear());
131 monthViewCtrl = new XCCalendarMonthView(this, _(""), wxDefaultPosition, wxDefaultSize, &NewGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
133 // Detach the old grid and attach the new one.
136 oldGrid->Show(false);
137 szrMain->Add(monthViewCtrl, 1, wxEXPAND, 5);
140 // Delete the old grid.
147 void XCCalendarCtrl::HideAccountEntries(wxCommandEvent &accountData){
149 // Get the list of calendar IDs for the account and go through
150 // the list of entries in each day control.
152 wxCommandEvent event(XCCALENDARMONTH_HIDEACCOUNTENTRIES);
153 event.SetInt(accountData.GetInt());
154 event.SetId(ID_HIDEENTRIES);
155 wxPostEvent(monthViewCtrl, event);
159 void XCCalendarCtrl::ShowAccountEntries(wxCommandEvent &accountData){
161 // Get the list of calendar IDs for the account and go through
162 // the list of entries in each day control.
164 wxCommandEvent event(XCCALENDARMONTH_SHOWACCOUNTENTRIES);
165 event.SetInt(accountData.GetInt());
166 event.SetId(ID_SHOWENTRIES);
167 wxPostEvent(monthViewCtrl, event);
171 void XCCalendarCtrl::HideCalendarEntries(wxCommandEvent &calendarData){
173 // Get the list of calendar IDs for the account and go through
174 // the list of entries in each day control.
176 wxCommandEvent event(XCCALENDARMONTH_HIDECALENDARENTRIES);
177 event.SetInt(calendarData.GetInt());
178 event.SetId(ID_HIDECALENDARENTRIES);
179 wxPostEvent(monthViewCtrl, event);
183 void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){
185 // Get the list of calendar IDs for the account and go through
186 // the list of entries in each day control.
188 wxCommandEvent event(XCCALENDARMONTH_SHOWCALENDARENTRIES);
189 event.SetInt(calendarData.GetInt());
190 event.SetId(ID_SHOWCALENDARENTRIES);
191 wxPostEvent(monthViewCtrl, event);
195 void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){
197 wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES);
198 event.SetInt(calendarData.GetInt());
199 event.SetId(ID_DELETECALENDARENTRIES);
200 wxPostEvent(monthViewCtrl, event);
204 void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){
206 wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY);
207 event.SetInt(eventData.GetInt());
208 event.SetId(ID_DELETEENTRY);
209 wxPostEvent(monthViewCtrl, event);
213 void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){
215 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
217 eventInfo->hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
218 eventInfo->hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
220 wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY);
221 addEvent.SetId(ID_ADDENTRY);
222 addEvent.SetClientData(eventInfo);
223 wxPostEvent(monthViewCtrl, addEvent);
227 void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){
229 EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
231 wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY);
232 addEvent.SetId(ID_UPDATEENTRY);
233 addEvent.SetClientData(eventInfo);
234 wxPostEvent(monthViewCtrl, addEvent);
238 void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){
240 ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
242 wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR);
243 colourEvent.SetId(ID_UPDATECOLOUR);
244 colourEvent.SetClientData(colourInfo);
245 wxPostEvent(monthViewCtrl, colourEvent);