Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
CalendarObject: Update code
[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 BEGIN_EVENT_TABLE(XCCalendarCtrl, wxPanel)
22 END_EVENT_TABLE()
24 using namespace std; 
26 XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorage)
27         : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize){
28         
29         // Setup the pointers.
30                 
31         calendarStorage = dataStorage;
32                 
33         // Setup the main sizer.
34         
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);
41         
42         // Setup the top menu.
43                 
44         ManipulatorCtrl = new XCCalendarManipulator(this, "XCCalendarManipulator Test", wxDefaultPosition, wxDefaultSize, calendarStorage);
45                 
46         // Setup the month view grid.
47         
48         wxDateTime DTNow = wxDateTime::Now();
49         int currentMonth = ((int)DTNow.GetMonth() + 1);
50         int currentYear = DTNow.GetYear();
51                 
52         XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear);
53         szrMain->Add(ManipulatorCtrl, 1, wxEXPAND, 5);
54                 
55         // Get the list of hidden accounts and calendars.
56                 
57         vector<int> hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
58         vector<int> hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
59                 
60         MonthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
61         szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
62         
63         // Connect events to the control.
64         
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));
75         
76 }
78 XCCalendarCtrl::~XCCalendarCtrl(){
79         
80         // Destory the controls in the XCCalendarCtrl class.
81         
82 }
84 void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
86         XCCalendarMonthView *OldGrid = nullptr;
87         
88         // Park the old grid.
90         OldGrid = MonthViewCtrl;
91         
92         // Get the list of hidden accounts and calendars.
93                 
94         vector<int> hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
95         vector<int> hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
96         
97         // Create a new grid.
98         
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.
103         
104         szrMain->Detach(1);
105         OldGrid->Show(false);
106         szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
107         szrMain->Layout();
108         
109         // Delete the old grid.
110         
111         delete OldGrid;
112         OldGrid = nullptr;
113         
116 void XCCalendarCtrl::HideAccountEntries(wxCommandEvent &accountData){
117         
118         // Get the list of calendar IDs for the account and go through 
119         // the list of entries in each day control.
120         
121         wxCommandEvent event(XCCALENDARMONTH_HIDEACCOUNTENTRIES);
122         event.SetInt(accountData.GetInt());
123         event.SetId(ID_HIDEENTRIES);
124         wxPostEvent(MonthViewCtrl, event);
125         
128 void XCCalendarCtrl::ShowAccountEntries(wxCommandEvent &accountData){
129         
130         // Get the list of calendar IDs for the account and go through 
131         // the list of entries in each day control.
132         
133         wxCommandEvent event(XCCALENDARMONTH_SHOWACCOUNTENTRIES);
134         event.SetInt(accountData.GetInt());
135         event.SetId(ID_SHOWENTRIES);
136         wxPostEvent(MonthViewCtrl, event);
137         
140 void XCCalendarCtrl::HideCalendarEntries(wxCommandEvent &calendarData){
141         
142         // Get the list of calendar IDs for the account and go through 
143         // the list of entries in each day control.
144         
145         wxCommandEvent event(XCCALENDARMONTH_HIDECALENDARENTRIES);
146         event.SetInt(calendarData.GetInt());
147         event.SetId(ID_HIDECALENDARENTRIES);
148         wxPostEvent(MonthViewCtrl, event);
149         
152 void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){
153         
154         // Get the list of calendar IDs for the account and go through 
155         // the list of entries in each day control.
156         
157         wxCommandEvent event(XCCALENDARMONTH_SHOWCALENDARENTRIES);
158         event.SetInt(calendarData.GetInt());
159         event.SetId(ID_SHOWCALENDARENTRIES);
160         wxPostEvent(MonthViewCtrl, event);
161         
164 void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){
165         
166         wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES);
167         event.SetInt(calendarData.GetInt());
168         event.SetId(ID_DELETECALENDARENTRIES);
169         wxPostEvent(MonthViewCtrl, event);
170         
173 void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){
174         
175         wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY);
176         event.SetInt(eventData.GetInt());
177         event.SetId(ID_DELETEENTRY);
178         wxPostEvent(MonthViewCtrl, event);
179         
182 void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){
183         
184         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
186         eventInfo->hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
187         eventInfo->hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
188         
189         wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY);
190         addEvent.SetId(ID_ADDENTRY);
191         addEvent.SetClientData(eventInfo);
192         wxPostEvent(MonthViewCtrl, addEvent);
193         
196 void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){
197         
198         EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
199         
200         wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY);
201         addEvent.SetId(ID_UPDATEENTRY);
202         addEvent.SetClientData(eventInfo);
203         wxPostEvent(MonthViewCtrl, addEvent);
204         
207 void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){
208         
209         ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
210         
211         wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR);
212         colourEvent.SetId(ID_UPDATECOLOUR);
213         colourEvent.SetClientData(colourInfo);
214         wxPostEvent(MonthViewCtrl, colourEvent);
215         
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