// 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);
// TODO: Get the list of hidden accounts and calendars.
vector hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
vector hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
MonthViewCtrl = new XCCalendarMonthView(this, "XCCalendarMonthView Test", wxDefaultPosition, wxDefaultSize, &CurrentMonthGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
szrMain->Add(MonthViewCtrl, 1, wxEXPAND, 5);
// Connect events to the control.
Connect(ID_CHANGEGRID, XCCALENDARCTRL_CHANGEGRID, wxCommandEventHandler(XCCalendarCtrl::UpdateGrid));
Connect(ID_HIDEENTRIES, XCCALENDARCTRL_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarCtrl::HideAccountEntries));
Connect(ID_SHOWENTRIES, XCCALENDARCTRL_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowAccountEntries));
Connect(ID_HIDECALENDARENTRIES, XCCALENDARCTRL_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::HideCalendarEntries));
Connect(ID_SHOWCALENDARENTRIES, XCCALENDARCTRL_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarCtrl::ShowCalendarEntries));
}
XCCalendarCtrl::~XCCalendarCtrl(){
// Destory the controls in the XCCalendarCtrl class.
}
void XCCalendarCtrl::UpdateGrid(wxCommandEvent &event){
XCCalendarMonthView *OldGrid = nullptr;
// Park the old grid.
OldGrid = MonthViewCtrl;
// Get the list of hidden accounts and calendars.
vector hideAccountsList = ManipulatorCtrl->GetHiddenAccountsList();
vector hideCalendarsList = ManipulatorCtrl->GetHiddenCalendarsList();
// Create a new grid.
XCCalendarMonthViewGrid NewGrid = GenerateMonthGrid(ManipulatorCtrl->GetMonth(), ManipulatorCtrl->GetYear());
MonthViewCtrl = new XCCalendarMonthView(this, _(""), wxDefaultPosition, wxDefaultSize, &NewGrid, calendarStorage, &hideAccountsList, &hideCalendarsList);
// 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;
}
void XCCalendarCtrl::HideAccountEntries(wxCommandEvent &accountData){
// Get the list of calendar IDs for the account and go through
// the list of entries in each day control.
wxCommandEvent event(XCCALENDARMONTH_HIDEACCOUNTENTRIES);
event.SetInt(accountData.GetInt());
event.SetId(ID_HIDEENTRIES);
wxPostEvent(MonthViewCtrl, event);
}
void XCCalendarCtrl::ShowAccountEntries(wxCommandEvent &accountData){
// Get the list of calendar IDs for the account and go through
// the list of entries in each day control.
wxCommandEvent event(XCCALENDARMONTH_SHOWACCOUNTENTRIES);
event.SetInt(accountData.GetInt());
event.SetId(ID_SHOWENTRIES);
wxPostEvent(MonthViewCtrl, event);
}
void XCCalendarCtrl::HideCalendarEntries(wxCommandEvent &calendarData){
// Get the list of calendar IDs for the account and go through
// the list of entries in each day control.
wxCommandEvent event(XCCALENDARMONTH_HIDECALENDARENTRIES);
event.SetInt(calendarData.GetInt());
event.SetId(ID_HIDECALENDARENTRIES);
wxPostEvent(MonthViewCtrl, event);
}
void XCCalendarCtrl::ShowCalendarEntries(wxCommandEvent &calendarData){
// Get the list of calendar IDs for the account and go through
// the list of entries in each day control.
wxCommandEvent event(XCCALENDARMONTH_SHOWCALENDARENTRIES);
event.SetInt(calendarData.GetInt());
event.SetId(ID_SHOWCALENDARENTRIES);
wxPostEvent(MonthViewCtrl, event);
}