// 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){
Connect(wxID_ANY, XCCALENDARDAY_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectOthersEvent));
Connect(ID_DESELECTALLITEMS, XCCALENDARDAY_DESELECTALLENTRIES, wxCommandEventHandler(XCCalendarDay::DeselectAllEvent));
this->SetMinSize( wxSize( 100,100 ) );
AlertIconBitmap.LoadFile("AlertIcon-32.png", wxBITMAP_DEFAULT_TYPE);
PriorityIconBitmap.LoadFile("PriorityIcon-32.png", wxBITMAP_DEFAULT_TYPE);
AlertIcon->SetBitmap(AlertIconBitmap);
HighPriorityIcon->SetBitmap(PriorityIconBitmap);
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);
CalendarEntry1->SetColour(&EventColour);
CalendarEntry1->SetDisplayAlarm(false);
CalendarEntry1->SetDisplayHighPriority(false);
EventListFrameSizer->Add(CalendarEntry1, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventColour.red = 255; EventColour.green = 0; EventColour.blue = 0;
CalendarEntry2->SetColour(&EventColour);
CalendarEntry2->SetDisplayAlarm(true);
CalendarEntry2->SetDisplayHighPriority(false);
EventListFrameSizer->Add(CalendarEntry2, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventColour.red = 0; EventColour.green = 255; EventColour.blue = 0;
CalendarEntry3->SetColour(&EventColour);
CalendarEntry3->SetDisplayAlarm(false);
CalendarEntry3->SetDisplayHighPriority(false);
EventListFrameSizer->Add(CalendarEntry3, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventColour.red = 0; EventColour.green = 0; EventColour.blue = 255;
CalendarEntry4->SetColour(&EventColour);
CalendarEntry4->SetDisplayAlarm(false);
CalendarEntry4->SetDisplayHighPriority(false);
EventListFrameSizer->Add(CalendarEntry4, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry5, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry6, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry7, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry8, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry9, 0, wxEXPAND, 5);
EventListFrameSizer->Add(0, 5, 0, 0, 5);
EventListFrameSizer->Add(CalendarEntry10, 0, wxEXPAND, 5);
EventListFrame->SetScrollRate(0,1);
//EventListFrameSizer->FitInside(EventListFrame);
EventListFrameSizer->Fit(EventListFrame);
EventListFrameSizer->Layout();
WindowSizer->Fit(this);
// Setup the scroll window.
WindowSizer->Add(TopSectionSizer, 1, wxEXPAND, 5);
WindowSizer->Add(MainSectionSizer, 1, wxEXPAND, 5);
MainSectionSizer->Add(EventListFrame, 1, wxGROW | wxALL, 10);
this->SetSizer(WindowSizer);
this->SetSize(size);
this->Layout();
this->SetBackgroundStyle(wxBG_STYLE_PAINT);
this->Centre(wxBOTH);
CalendarEntryList.push_back(CalendarEntry1);
CalendarEntryList.push_back(CalendarEntry2);
CalendarEntryList.push_back(CalendarEntry3);
CalendarEntryList.push_back(CalendarEntry4);
CalendarEntryList.push_back(CalendarEntry5);
CalendarEntryList.push_back(CalendarEntry6);
CalendarEntryList.push_back(CalendarEntry7);
CalendarEntryList.push_back(CalendarEntry8);
CalendarEntryList.push_back(CalendarEntry9);
CalendarEntryList.push_back(CalendarEntry10);
UpdateTopIcons();
}
XCCalendarDay::~XCCalendarDay(){
// Destory the controls from the widget.
}
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);
for (vector::iterator EntryIter = CalendarEntryList.begin();
EntryIter != CalendarEntryList.end(); EntryIter++){
if ((*EntryIter)->GetID() != SelectedEntryID){
wxPostEvent((*EntryIter), DeselectEntryEvent);
}
}
}
void XCCalendarDay::SetupControl(int SetupDay, int SetupMonth, int SetupYear, bool SetupIsInMonth, XCCalendarMonthView *MonthViewPointer)
{
// Set the day
NumberText->SetLabel(wxString::Format("%02i", SetupDay));
// Set the month
// Set the year.
// Setup the Is In Month value.
IsInMonth = SetupIsInMonth;
// Setup the month view pointer.
this->MonthViewPointer = MonthViewPointer;
}