Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarCtrl.cpp
1 // XCCalendarCtrl.cpp - Xestia Calendar XCCalendarCtrl 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 "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);
32 using namespace std; 
34 XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorage)
35         : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize){
36         // Setup the pointers.
37                 
38         calendarStorage = dataStorage;
39                 
40         // Setup the main sizer.
41         
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);
48         
49         // Setup the top menu.
50                 
51         manipulatorCtrl = new XCCalendarManipulator(this, "XCCalendarManipulator Test", wxDefaultPosition, wxDefaultSize, calendarStorage);
52                 
53         // Setup the month view grid.
54         
55         wxDateTime dtNow = wxDateTime::Now();
56         int currentMonth = ((int)dtNow.GetMonth() + 1);
57         int currentYear = dtNow.GetYear();
58                 
59         XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear);
60         szrMain->Add(manipulatorCtrl, 1, wxEXPAND, 5);
61                 
62         // Get the list of hidden accounts and calendars.
63                 
64         vector<int> hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
65         vector<int> hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
66                 
67         monthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
68         szrMain->Add(monthViewCtrl, 1, wxEXPAND, 5);
69         
70         // Bind events to the control.
71         
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);
83 }
85 XCCalendarCtrl::~XCCalendarCtrl(){
86         
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);
100         
101         szrMain->Clear();
102         
103         delete monthViewCtrl;
104         monthViewCtrl = nullptr;
105         
106         delete manipulatorCtrl;
107         manipulatorCtrl = nullptr;
108         
109         calendarStorage = nullptr;
110         
111         this->SetSizer(nullptr, true);
112         
115 void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
117         XCCalendarMonthView *oldGrid = nullptr;
118         
119         // Park the old grid.
121         oldGrid = monthViewCtrl;
122         
123         // Get the list of hidden accounts and calendars.
124                 
125         vector<int> hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
126         vector<int> hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
127         
128         // Create a new grid.
129         
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.
134         
135         szrMain->Detach(1);
136         oldGrid->Show(false);
137         szrMain->Add(monthViewCtrl, 1, wxEXPAND, 5);
138         szrMain->Layout();
139         
140         // Delete the old grid.
141         
142         delete oldGrid;
143         oldGrid = nullptr;
144         
147 void XCCalendarCtrl::HideAccountEntries(wxCommandEvent &accountData){
148         
149         // Get the list of calendar IDs for the account and go through 
150         // the list of entries in each day control.
151         
152         wxCommandEvent event(XCCALENDARMONTH_HIDEACCOUNTENTRIES);
153         event.SetInt(accountData.GetInt());
154         event.SetId(ID_HIDEENTRIES);
155         wxPostEvent(monthViewCtrl, event);
156         
159 void XCCalendarCtrl::ShowAccountEntries(wxCommandEvent &accountData){
160         
161         // Get the list of calendar IDs for the account and go through 
162         // the list of entries in each day control.
163         
164         wxCommandEvent event(XCCALENDARMONTH_SHOWACCOUNTENTRIES);
165         event.SetInt(accountData.GetInt());
166         event.SetId(ID_SHOWENTRIES);
167         wxPostEvent(monthViewCtrl, event);
168         
171 void XCCalendarCtrl::HideCalendarEntries(wxCommandEvent &calendarData){
172         
173         // Get the list of calendar IDs for the account and go through 
174         // the list of entries in each day control.
175         
176         wxCommandEvent event(XCCALENDARMONTH_HIDECALENDARENTRIES);
177         event.SetInt(calendarData.GetInt());
178         event.SetId(ID_HIDECALENDARENTRIES);
179         wxPostEvent(monthViewCtrl, event);
180         
183 void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){
184         
185         // Get the list of calendar IDs for the account and go through 
186         // the list of entries in each day control.
187         
188         wxCommandEvent event(XCCALENDARMONTH_SHOWCALENDARENTRIES);
189         event.SetInt(calendarData.GetInt());
190         event.SetId(ID_SHOWCALENDARENTRIES);
191         wxPostEvent(monthViewCtrl, event);
192         
195 void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){
196         
197         wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES);
198         event.SetInt(calendarData.GetInt());
199         event.SetId(ID_DELETECALENDARENTRIES);
200         wxPostEvent(monthViewCtrl, event);
201         
204 void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){
205         
206         wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY);
207         event.SetInt(eventData.GetInt());
208         event.SetId(ID_DELETEENTRY);
209         wxPostEvent(monthViewCtrl, event);
210         
213 void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){
214         
215         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
217         eventInfo->hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
218         eventInfo->hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
219         
220         wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY);
221         addEvent.SetId(ID_ADDENTRY);
222         addEvent.SetClientData(eventInfo);
223         wxPostEvent(monthViewCtrl, addEvent);
224         
227 void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){
228         
229         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
230         
231         wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY);
232         addEvent.SetId(ID_UPDATEENTRY);
233         addEvent.SetClientData(eventInfo);
234         wxPostEvent(monthViewCtrl, addEvent);
235         
238 void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){
239         
240         ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
241         
242         wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR);
243         colourEvent.SetId(ID_UPDATECOLOUR);
244         colourEvent.SetClientData(colourInfo);
245         wxPostEvent(monthViewCtrl, colourEvent);
246         
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