// XCCalendarMonthView.cpp - Xestia Calendar XCCalendarMonthView 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 "XCCalendarMonthView.h"
using namespace std;
BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
EVT_PAINT(XCCalendarMonthView::PaintFrameEvent)
END_EVENT_TABLE()
XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector *hideAccounts, std::vector *hideCalendars)
: wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL){
calendarStorage = dataStorage;
MondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
TuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
WednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
ThursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
FridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
SaturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
SundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
WindowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(WednesdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(ThursdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(FridayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(SaturdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(SundayText, 1, wxEXPAND|wxALL, 0);
ProcessGrid(grid, hideAccounts, hideCalendars);
// Setup the days.
// Setup the growable rows and columns.
WindowSizer->AddGrowableCol(0);
WindowSizer->AddGrowableCol(1);
WindowSizer->AddGrowableCol(2);
WindowSizer->AddGrowableCol(3);
WindowSizer->AddGrowableCol(4);
WindowSizer->AddGrowableCol(5);
WindowSizer->AddGrowableCol(6);
WindowSizer->SetFlexibleDirection( wxBOTH );
WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
this->SetSizer(WindowSizer);
WindowSizer->Fit(this);
this->Layout();
this->SetBackgroundColour(wxColour(0,0,0));
Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
Connect(ID_HIDEENTRIES, XCCALENDARMONTH_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideAccountEntries));
Connect(ID_SHOWENTRIES, XCCALENDARMONTH_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowAccountEntries));
Connect(ID_HIDECALENDARENTRIES, XCCALENDARMONTH_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideCalendarEntries));
Connect(ID_SHOWCALENDARENTRIES, XCCALENDARMONTH_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowCalendarEntries));
}
XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector *hideAccounts, std::vector *hideCalendars)
: wxPanel(NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){
Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
calendarStorage = dataStorage;
MondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
TuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
WednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
ThursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
FridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
SaturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
SundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
WindowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(WednesdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(ThursdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(FridayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(SaturdayText, 1, wxEXPAND|wxALL, 0);
WindowSizer->Add(SundayText, 1, wxEXPAND|wxALL, 0);
ProcessGrid(grid, hideAccounts, hideCalendars);
// Setup the days.
// Setup the growable rows and columns.
WindowSizer->AddGrowableCol(0);
WindowSizer->AddGrowableCol(1);
WindowSizer->AddGrowableCol(2);
WindowSizer->AddGrowableCol(3);
WindowSizer->AddGrowableCol(4);
WindowSizer->AddGrowableCol(5);
WindowSizer->AddGrowableCol(6);
WindowSizer->SetFlexibleDirection( wxBOTH );
WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
this->SetSizer(WindowSizer);
WindowSizer->Fit(this);
this->Layout();
this->SetBackgroundColour(wxColour(0,0,0));
}
XCCalendarMonthView::~XCCalendarMonthView(){
}
void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector *hideAccounts, std::vector *hideCalendars){
// TODO: Delete the old calendar entries.
// Add the new calendar entries.
int Week = 0;
for (vector::iterator WeekIter = grid->WeekList.begin();
WeekIter != grid->WeekList.end(); WeekIter++){
Week++;
for (vector::iterator DayIter = (*WeekIter).DayList.begin();
DayIter != (*WeekIter).DayList.end(); DayIter++){
// TODO: Add CalendarEntries.
XCCalendarDay *CalendarDayItem = new XCCalendarDay(this, "XCCalendarMonthView Test", wxPoint(50, 50), wxSize(200, 200));
// Setup the control.
CalendarDayItem->SetupControl((*DayIter).Day, (*DayIter).Month, (*DayIter).Year, (*DayIter).IsInMonth, this, calendarStorage, hideAccounts, hideCalendars);
CalendarDayList.push_back(CalendarDayItem);
WindowSizer->Add(CalendarDayItem, 1, wxEXPAND, 5);
}
}
// Add the Growable Rows.
for (int WeekSeek = 0; WeekSeek < Week; WeekSeek++){
WindowSizer->AddGrowableRow((WeekSeek + 1));
}
}
void XCCalendarMonthView::Repaint(){
// Draw the border.
this->Layout();
}
void XCCalendarMonthView::PaintFrameEvent(wxPaintEvent &PaintEvent){
Repaint();
}
void XCCalendarMonthView::ResizeFrameEvent(wxSizeEvent &SizeEvent){
// TODO: Check if window size is less than 120 pixels and if it is,
// switch to the small block mode.
// Refresh the window.
this->Refresh();
}
void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &DeselectEvent){
for (vector::iterator DayIter = CalendarDayList.begin();
DayIter != CalendarDayList.end(); DayIter++){
if (DeselectEvent.GetClientData() != (void*)(*DayIter)){
wxCommandEvent DeselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
DeselectEvent.SetId(ID_DESELECTALLITEMS);
wxPostEvent((*DayIter), DeselectEvent);
}
}
}
void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
for (vector::iterator DayIter = CalendarDayList.begin();
DayIter != CalendarDayList.end(); DayIter++){
wxCommandEvent HideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
HideEvent.SetInt(accountData.GetInt());
HideEvent.SetId(ID_HIDEENTRIES);
wxPostEvent((*DayIter), HideEvent);
}
}
void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
for (vector::iterator DayIter = CalendarDayList.begin();
DayIter != CalendarDayList.end(); DayIter++){
wxCommandEvent ShowEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
ShowEvent.SetInt(accountData.GetInt());
ShowEvent.SetId(ID_SHOWENTRIES);
wxPostEvent((*DayIter), ShowEvent);
}
}
void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
for (vector::iterator DayIter = CalendarDayList.begin();
DayIter != CalendarDayList.end(); DayIter++){
wxCommandEvent HideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
HideEvent.SetInt(accountData.GetInt());
HideEvent.SetId(ID_HIDECALENDARENTRIES);
wxPostEvent((*DayIter), HideEvent);
}
}
void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
for (vector::iterator DayIter = CalendarDayList.begin();
DayIter != CalendarDayList.end(); DayIter++){
wxCommandEvent HideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
HideEvent.SetInt(accountData.GetInt());
HideEvent.SetId(ID_SHOWCALENDARENTRIES);
wxPostEvent((*DayIter), HideEvent);
}
}