// XCCalendarDay.cpp - Xestia Calendar XCCalendarDay 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 "XCCalendarDay.h"
using namespace std;
BEGIN_EVENT_TABLE(XCCalendarDay, wxPanel)
EVT_PAINT(XCCalendarDay::PaintFrameEvent)
EVT_SIZE(XCCalendarDay::ResizeFrameEvent)
END_EVENT_TABLE()
XCCalendarDay::XCCalendarDay(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size)
: wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
this->SetMinSize( wxSize( 100,100 ) );
// Setip the icons.
wxMemoryInputStream alerticon(icons_alert32_png, sizeof(icons_alert32_png));
wxMemoryInputStream priorityicon(icons_priority32_png, sizeof(icons_priority32_png));
wxImage icons_alert_png(alerticon, wxBITMAP_TYPE_PNG);
wxBitmap imgAlertIcon(icons_alert_png, -1);
wxImage icons_priority_png(priorityicon, wxBITMAP_TYPE_PNG);
wxBitmap imgPriorityIcon(icons_priority_png, -1);
AlertIcon->SetBitmap(imgAlertIcon);
HighPriorityIcon->SetBitmap(imgPriorityIcon);
WindowSizer->AddGrowableCol(0);
WindowSizer->AddGrowableRow(1);
WindowSizer->SetFlexibleDirection( wxBOTH );
WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
NumberText = new wxStaticText(this, wxID_ANY, wxT("09"), wxDefaultPosition, wxDefaultSize, 0);
NumberText->SetFont(wxFont(24, 70, 90, 92, false, wxEmptyString));
TopSectionSizer->Add(HighPriorityIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
TopSectionSizer->Add(AlertIcon, 0, wxALL|wxALIGN_CENTER_VERTICAL, 0);
TopSectionSizer->Add(0, 0, 1, wxEXPAND, 5);
TopSectionSizer->Add(NumberText, 0, wxALL|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
// Setup the scrollable section.
Colour EventColour;
EventColour.red = 40; EventColour.green = 80; EventColour.blue = 80;
EventListFrame->SetSizer(EventListFrameSizer);
EventListFrame->SetScrollRate(0,1);
//EventListFrameSizer->FitInside(EventListFrame);
EventListFrameSizer->Fit(EventListFrame);
EventListFrameSizer->Layout();
WindowSizer->Fit(this);
// Setup the scroll window.
MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
this->SetSizer(WindowSizer);
this->SetSize(size);
this->Layout();
this->SetBackgroundStyle(wxBG_STYLE_PAINT);
this->Centre(wxBOTH);
UpdateTopIcons();
Connect(ID_DESELECTOTHERENTRIES, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
Connect(ID_HIDEENTRIES, XCCALENDARDAY_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::HideAccountEntries));
Connect(ID_SHOWENTRIES, XCCALENDARDAY_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarDay::ShowAccountEntries));
Connect(ID_HIDECALENDARENTRIES, XCCALENDARDAY_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::HideCalendarEntries));
Connect(ID_SHOWCALENDARENTRIES, XCCALENDARDAY_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarDay::ShowCalendarEntries));
}
XCCalendarDay::~XCCalendarDay(){
// Destory the controls from the widget.
for (vector::iterator CalendarEntryIter = CalendarEntryList.begin();
CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
delete((*CalendarEntryIter));
}
CalendarEntryList.clear();
this->Refresh();
}
void XCCalendarDay::Repaint(){
wxPaintDC dc(this);
wxPaintDC EventListFrameDC(EventListFrame);
// Get the wxSizerItem for the top date and the entries part.
wxSizerItem *TopSectionSizerItem = WindowSizer->GetItem((size_t)0);
wxSizerItem *MainSectionSizerItem = WindowSizer->GetItem((size_t)1);
wxRect TopSizer = wxRect(WindowSizer->GetPosition(), WindowSizer->GetSize());
if (IsInMonth == true){
dc.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
dc.SetBrush(wxBrush(wxColor(255,255,255)));
dc.DrawRectangle(TopSectionSizerItem->GetRect());
dc.SetBrush(wxBrush(wxColor(225,225,225)));
dc.DrawRectangle(MainSectionSizerItem->GetRect());
EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
EventListFrameDC.SetBrush(wxBrush(wxColor(225,225,225)));
EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
} else {
dc.SetPen(wxPen(wxColor(185,185,185), 0, wxPENSTYLE_TRANSPARENT));
dc.SetBrush(wxBrush(wxColor(185,185,185)));
dc.DrawRectangle(TopSectionSizerItem->GetRect());
dc.SetBrush(wxBrush(wxColor(155,155,155)));
dc.DrawRectangle(MainSectionSizerItem->GetRect());
EventListFrameDC.SetPen(wxPen(wxColor(255,255,255), 0, wxPENSTYLE_TRANSPARENT));
EventListFrameDC.SetBrush(wxBrush(wxColor(155,155,155)));
EventListFrameDC.DrawRectangle(EventListFrame->GetClientRect());
}
// Draw the border.
//dc.SetBrush(wxBrush(wxColor(0,0,0), wxBRUSHSTYLE_TRANSPARENT));
this->Layout();
}
void XCCalendarDay::UpdateTopIcons(){
bool AlarmFound = false;
bool HighPriorityFound = false;
for (vector::iterator EntryIter = CalendarEntryList.begin();
EntryIter != CalendarEntryList.end(); EntryIter++){
if ((*EntryIter)->GetDisplayAlarm() == true){
AlarmFound = true;
}
if ((*EntryIter)->GetDisplayHighPriority() == true){
HighPriorityFound = true;
}
if (AlarmFound == true && HighPriorityFound == true){
break;
}
}
AlertIcon->Show(AlarmFound);
HighPriorityIcon->Show(HighPriorityFound);
}
void XCCalendarDay::PaintFrameEvent(wxPaintEvent &PaintEvent)
{
Repaint();
}
void XCCalendarDay::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 XCCalendarDay::DeselectOthersEvent(wxCommandEvent &DeselectEvent)
{
int SelectedEntryID = DeselectEvent.GetInt();
wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
for (vector::iterator EntryIter = CalendarEntryList.begin();
EntryIter != CalendarEntryList.end(); EntryIter++){
if ((*EntryIter)->GetID() != SelectedEntryID){
wxPostEvent((*EntryIter), DeselectEntryEvent);
}
}
// Send event notification to deselect the other calendar entries.
if (this->MonthViewPointer != nullptr){
wxCommandEvent DeselectEvent(XCCALENDARMONTH_DESELECTOTHERENTRIES);
DeselectEvent.SetClientData(this);
DeselectEvent.SetId(ID_MONTHVIEWCLEARSELECTION);
wxPostEvent(this->MonthViewPointer, DeselectEvent);
}
}
void XCCalendarDay::DeselectAllEvent(wxCommandEvent &DeselectEvent)
{
int SelectedEntryID = DeselectEvent.GetInt();
wxCommandEvent DeselectEntryEvent(XCCALENDARDAYENTRY_DESELECT);
DeselectEntryEvent.SetId(ID_ENTRYDESELECT);
for (vector::iterator EntryIter = CalendarEntryList.begin();
EntryIter != CalendarEntryList.end(); EntryIter++){
wxPostEvent((*EntryIter), DeselectEntryEvent);
}
}
void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer, CalendarDataStorage *dataStorage, vector *hideAccounts, vector *hideCalendars)
{
// Set the day
NumberText->SetLabel(wxString::Format("%02i", SetupDay));
calendarDay = SetupDay;
// Set the month
calendarMonth = SetupMonth;
// Set the year.
calendarYear = SetupYear;
// Setup the Is In Month value.
IsInMonth = SetupIsInMonth;
// Setup the month view pointer.
this->MonthViewPointer = MonthViewPointer;
// Setup the calendar items.
CDSEntryList calendarItems = dataStorage->GetEventListByDate(SetupYear, SetupMonth, SetupDay);
for (int entrySeek = 0; entrySeek < calendarItems.entryList.size(); entrySeek++){
// Get the information about the calendar entry.
CDSGetCalendarEntryInfo newEntryInfo = dataStorage->GetEvent(calendarItems.entryList[entrySeek]);
CDSGetCalendarInfo newEntryCalendarInfo = dataStorage->GetCalendar(newEntryInfo.calendarID);
// Setup the calendar entry.
XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(EventListFrame, newEntryInfo.entryName, wxDefaultPosition, wxDefaultSize, calendarItems.entryList[entrySeek]);
newEntry->SetColour(&newEntryCalendarInfo.calendarColour);
newEntry->SetTime(newEntryInfo.entryStartHour, newEntryInfo.entryStartMinute, newEntryInfo.entryStartSecond);
newEntry->SetEntryIDs(newEntryCalendarInfo.accountID, newEntryInfo.calendarID, newEntryInfo.calendarEntryID);
EventListFrameSizer->Add(newEntry, 0, wxEXPAND, 5);
wxSizerItem *afterSpacer = EventListFrameSizer->Add(0, 5, 0, 0, 5);
newEntry->SetAfterSpacer(afterSpacer);
// Go through the list of calendar entries to hide by account.
for (vector::iterator hideAccountsItem = hideAccounts->begin();
hideAccountsItem != hideAccounts->end(); hideAccountsItem++){
if (*hideAccountsItem = newEntryCalendarInfo.accountID){
newEntry->Show(false);
newEntry->GetAfterSpacer()->Show(false);
}
}
// Go through the list of calendar entries to hide by calendar.
for (vector::iterator hideCalendarsItem = hideCalendars->begin();
hideCalendarsItem != hideCalendars->end(); hideCalendarsItem++){
if (*hideCalendarsItem == newEntryInfo.calendarID){
newEntry->Show(false);
newEntry->GetAfterSpacer()->Show(false);
}
}
CalendarEntryList.push_back(newEntry);
}
}
void XCCalendarDay::HideAccountEntries(wxCommandEvent &accountData){
// Go through each of the controls and hide the controls (and spacing) that
// have the matched account IDs.
int sizerPosition = 0;
for (vector::iterator CalendarEntryIter = CalendarEntryList.begin();
CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
(*CalendarEntryIter)->SetShowAccountStatus(false);
if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
(*CalendarEntryIter)->Show(false);
// Get the spacing and hide it as well.
wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
afterSpacer->Show(false);
}
}
this->Refresh();
Repaint();
}
void XCCalendarDay::ShowAccountEntries(wxCommandEvent &accountData){
// Go through each of the controls and hide the controls (and spacing) that
// have the matched account IDs.
int sizerPosition = 0;
for (vector::iterator CalendarEntryIter = CalendarEntryList.begin();
CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
(*CalendarEntryIter)->SetShowAccountStatus(true);
if ((*CalendarEntryIter)->GetShowCalendarStatus() == false){
continue;
}
if ((*CalendarEntryIter)->GetAccountID() == accountData.GetInt()){
wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
(*CalendarEntryIter)->Show(true);
// Get the spacing and hide it as well.
wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
afterSpacer->Show(true);
}
}
this->Refresh();
Repaint();
}
void XCCalendarDay::HideCalendarEntries(wxCommandEvent &calendarData){
// Go through each of the controls and hide the controls (and spacing) that
// have the matched account IDs.
int sizerPosition = 0;
for (vector::iterator CalendarEntryIter = CalendarEntryList.begin();
CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
(*CalendarEntryIter)->SetShowCalendarStatus(false);
wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
(*CalendarEntryIter)->Show(false);
// Get the spacing and hide it as well.
wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
afterSpacer->Show(false);
}
}
this->Refresh();
Repaint();
}
void XCCalendarDay::ShowCalendarEntries(wxCommandEvent &calendarData){
// Go through each of the controls and hide the controls (and spacing) that
// have the matched account IDs.
int sizerPosition = 0;
for (vector::iterator CalendarEntryIter = CalendarEntryList.begin();
CalendarEntryIter != CalendarEntryList.end(); CalendarEntryIter++){
if ((*CalendarEntryIter)->GetCalendarID() == calendarData.GetInt()){
(*CalendarEntryIter)->SetShowCalendarStatus(true);
if ((*CalendarEntryIter)->GetShowAccountStatus() == false){
// Don't show the calendar entry because the account status
// is set to hidden. Continue to the next one.
continue;
}
wxSizerItem *calendarItem = EventListFrameSizer->GetItem((*CalendarEntryIter));
(*CalendarEntryIter)->Show(true);
// Get the spacing and hide it as well.
wxSizerItem *afterSpacer = (*CalendarEntryIter)->GetAfterSpacer();
afterSpacer->Show(true);
}
}
this->Refresh();
Repaint();
}