// XCCalendarCtrl.cpp - Xestia Calendar XCCalendarCtrl widget class. // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "XCCalendarCtrl.h" BEGIN_EVENT_TABLE(XCCalendarCtrl, wxPanel) END_EVENT_TABLE() using namespace std; XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorage) : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize){ // Setup the pointers. calendarStorage = dataStorage; // Setup the main sizer. szrMain = new wxFlexGridSizer(2, 1, 0, 0); szrMain->AddGrowableCol(0); szrMain->AddGrowableRow(1); szrMain->SetFlexibleDirection(wxBOTH); szrMain->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); this->SetSizer(szrMain); // Setup the top menu. ManipulatorCtrl = new XCCalendarManipulator(this, "XCCalendarManipulator Test", wxDefaultPosition, wxDefaultSize, calendarStorage); // Setup the month view grid. wxDateTime DTNow = wxDateTime::Now(); int currentMonth = ((int)DTNow.GetMonth() + 1); int currentYear = DTNow.GetYear(); XCCalendarMonthViewGrid CurrentMonthGrid = GenerateMonthGrid(currentMonth, currentYear); szrMain->Add(ManipulatorCtrl, 1, wxEXPAND, 5); MonthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage); szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5); Connect(wxID_ANY, XCCALENDARCTRL_CHANGEGRID, wxCommandEventHandler(XCCalendarCtrl::UpdateGrid)); } XCCalendarCtrl::~XCCalendarCtrl(){ // Destory the controls in the XCCalendarCtrl class. } void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){ XCCalendarMonthView *OldGrid = nullptr; // Park the old grid. OldGrid = MonthViewCtrl; // Create a new grid. XCCalendarMonthViewGrid NewGrid = GenerateMonthGrid(ManipulatorCtrl->GetMonth(), ManipulatorCtrl->GetYear()); MonthViewCtrl = new XCCalendarMonthView(this, _(""), wxDefaultPosition, wxDefaultSize, &NewGrid, calendarStorage); // Detach the old grid and attach the new one. szrMain->Detach(1); OldGrid->Show(false); szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5); szrMain->Layout(); // Delete the old grid. delete OldGrid; OldGrid = nullptr; }