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 MonthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage);
56 szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
58 Connect(wxID_ANY, XCCALENDARCTRL_CHANGEGRID, wxCommandEventHandler(XCCalendarCtrl::UpdateGrid));
62 XCCalendarCtrl::~XCCalendarCtrl(){
64 // Destory the controls in the XCCalendarCtrl class.
68 void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
70 XCCalendarMonthView *OldGrid = nullptr;
74 OldGrid = MonthViewCtrl;
78 XCCalendarMonthViewGrid NewGrid = GenerateMonthGrid(ManipulatorCtrl->GetMonth(), ManipulatorCtrl->GetYear());
79 MonthViewCtrl = new XCCalendarMonthView(this, _(""), wxDefaultPosition, wxDefaultSize, &NewGrid, calendarStorage);
81 // Detach the old grid and attach the new one.
85 szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
88 // Delete the old grid.