// 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"
wxDEFINE_EVENT(XCCALENDARCTRL_CHANGEGRID, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_HIDEACCOUNTENTRIES, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_SHOWACCOUNTENTRIES, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_HIDECALENDARENTRIES, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_SHOWCALENDARENTRIES, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_DELETECALENDARENTRIES, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_ADDENTRY, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_UPDATEENTRY, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_UPDATECALENDARCOLOUR, wxCommandEvent);
wxDEFINE_EVENT(XCCALENDARCTRL_DELETEENTRY, wxCommandEvent);
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);
// 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);
// Bind events to the control.
Bind(XCCALENDARCTRL_CHANGEGRID, &XCCalendarCtrl::UpdateGrid, this, ID_CHANGEGRID);
Bind(XCCALENDARCTRL_HIDEACCOUNTENTRIES, &XCCalendarCtrl::HideAccountEntries, this, ID_HIDEENTRIES);
Bind(XCCALENDARCTRL_SHOWACCOUNTENTRIES, &XCCalendarCtrl::ShowAccountEntries, this, ID_SHOWENTRIES);
Bind(XCCALENDARCTRL_HIDECALENDARENTRIES, &XCCalendarCtrl::HideCalendarEntries, this, ID_HIDECALENDARENTRIES);
Bind(XCCALENDARCTRL_SHOWCALENDARENTRIES, &XCCalendarCtrl::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES);
Bind(XCCALENDARCTRL_DELETECALENDARENTRIES, &XCCalendarCtrl::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES);
Bind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
Bind(XCCALENDARCTRL_ADDENTRY, &XCCalendarCtrl::AddCalendarEntry, this, ID_ADDENTRY);
Bind(XCCALENDARCTRL_UPDATEENTRY, &XCCalendarCtrl::UpdateCalendarEntry, this, ID_UPDATEENTRY);
Bind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY);
Bind(XCCALENDARCTRL_UPDATECALENDARCOLOUR, &XCCalendarCtrl::UpdateCalendarColour, this, ID_UPDATECOLOUR);
}
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);
}
void XCCalendarCtrl::DeleteCalendarEntries(wxCommandEvent &calendarData){
wxCommandEvent event(XCCALENDARMONTH_DELETECALENDARENTRIES);
event.SetInt(calendarData.GetInt());
event.SetId(ID_DELETECALENDARENTRIES);
wxPostEvent(monthViewCtrl, event);
}
void XCCalendarCtrl::DeleteCalendarEntry(wxCommandEvent &eventData){
wxCommandEvent event(XCCALENDARMONTH_DELETEENTRY);
event.SetInt(eventData.GetInt());
event.SetId(ID_DELETEENTRY);
wxPostEvent(monthViewCtrl, event);
}
void XCCalendarCtrl::AddCalendarEntry(wxCommandEvent &eventData){
EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
eventInfo->hideAccountsList = manipulatorCtrl->GetHiddenAccountsList();
eventInfo->hideCalendarsList = manipulatorCtrl->GetHiddenCalendarsList();
wxCommandEvent addEvent(XCCALENDARMONTH_ADDENTRY);
addEvent.SetId(ID_ADDENTRY);
addEvent.SetClientData(eventInfo);
wxPostEvent(monthViewCtrl, addEvent);
}
void XCCalendarCtrl::UpdateCalendarEntry(wxCommandEvent &eventData){
EventProperties *eventInfo = (EventProperties*)eventData.GetClientData();
wxCommandEvent addEvent(XCCALENDARMONTH_UPDATEENTRY);
addEvent.SetId(ID_UPDATEENTRY);
addEvent.SetClientData(eventInfo);
wxPostEvent(monthViewCtrl, addEvent);
}
void XCCalendarCtrl::UpdateCalendarColour(wxCommandEvent &colourData){
ColourUpdateProperties *colourInfo = (ColourUpdateProperties*)colourData.GetClientData();
wxCommandEvent colourEvent(XCCALENDARMONTH_UPDATECALENDARCOLOUR);
colourEvent.SetId(ID_UPDATECOLOUR);
colourEvent.SetClientData(colourInfo);
wxPostEvent(monthViewCtrl, colourEvent);
}