1 // XCCalendarMonthView.cpp - Xestia Calendar XCCalendarMonthView widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "XCCalendarMonthView.h"
23 BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
24 EVT_PAINT(XCCalendarMonthView::PaintFrameEvent)
27 XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title, const wxPoint& pos, const wxSize& size, XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
28 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL){
30 calendarStorage = dataStorage;
32 MondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
33 TuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
34 WednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
35 ThursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
36 FridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
37 SaturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
38 SundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
40 WindowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0);
41 WindowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0);
42 WindowSizer->Add(WednesdayText, 1, wxEXPAND|wxALL, 0);
43 WindowSizer->Add(ThursdayText, 1, wxEXPAND|wxALL, 0);
44 WindowSizer->Add(FridayText, 1, wxEXPAND|wxALL, 0);
45 WindowSizer->Add(SaturdayText, 1, wxEXPAND|wxALL, 0);
46 WindowSizer->Add(SundayText, 1, wxEXPAND|wxALL, 0);
48 ProcessGrid(grid, hideAccounts, hideCalendars);
52 // Setup the growable rows and columns.
54 WindowSizer->AddGrowableCol(0);
55 WindowSizer->AddGrowableCol(1);
56 WindowSizer->AddGrowableCol(2);
57 WindowSizer->AddGrowableCol(3);
58 WindowSizer->AddGrowableCol(4);
59 WindowSizer->AddGrowableCol(5);
60 WindowSizer->AddGrowableCol(6);
61 WindowSizer->SetFlexibleDirection( wxBOTH );
62 WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
64 this->SetSizer(WindowSizer);
65 WindowSizer->Fit(this);
67 this->SetBackgroundColour(wxColour(0,0,0));
69 Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
70 Connect(ID_HIDEENTRIES, XCCALENDARMONTH_HIDEACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideAccountEntries));
71 Connect(ID_SHOWENTRIES, XCCALENDARMONTH_SHOWACCOUNTENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowAccountEntries));
72 Connect(ID_HIDECALENDARENTRIES, XCCALENDARMONTH_HIDECALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::HideCalendarEntries));
73 Connect(ID_SHOWCALENDARENTRIES, XCCALENDARMONTH_SHOWCALENDARENTRIES, wxCommandEventHandler(XCCalendarMonthView::ShowCalendarEntries));
77 XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
78 : wxPanel(NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){
80 Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
82 calendarStorage = dataStorage;
84 MondayText = new XCCalendarMonthViewDayTitle(this, _("Monday"), wxDefaultPosition, wxDefaultSize);
85 TuesdayText = new XCCalendarMonthViewDayTitle(this, _("Tuesday"), wxDefaultPosition, wxDefaultSize);
86 WednesdayText = new XCCalendarMonthViewDayTitle(this, _("Wednesday"), wxDefaultPosition, wxDefaultSize);
87 ThursdayText = new XCCalendarMonthViewDayTitle(this, _("Thursday"), wxDefaultPosition, wxDefaultSize);
88 FridayText = new XCCalendarMonthViewDayTitle(this, _("Friday"), wxDefaultPosition, wxDefaultSize);
89 SaturdayText = new XCCalendarMonthViewDayTitle(this, _("Saturday"), wxDefaultPosition, wxDefaultSize);
90 SundayText = new XCCalendarMonthViewDayTitle(this, _("Sunday"), wxDefaultPosition, wxDefaultSize);
92 WindowSizer->Add(MondayText, 1, wxEXPAND|wxALL, 0);
93 WindowSizer->Add(TuesdayText, 1, wxEXPAND|wxALL, 0);
94 WindowSizer->Add(WednesdayText, 1, wxEXPAND|wxALL, 0);
95 WindowSizer->Add(ThursdayText, 1, wxEXPAND|wxALL, 0);
96 WindowSizer->Add(FridayText, 1, wxEXPAND|wxALL, 0);
97 WindowSizer->Add(SaturdayText, 1, wxEXPAND|wxALL, 0);
98 WindowSizer->Add(SundayText, 1, wxEXPAND|wxALL, 0);
100 ProcessGrid(grid, hideAccounts, hideCalendars);
104 // Setup the growable rows and columns.
106 WindowSizer->AddGrowableCol(0);
107 WindowSizer->AddGrowableCol(1);
108 WindowSizer->AddGrowableCol(2);
109 WindowSizer->AddGrowableCol(3);
110 WindowSizer->AddGrowableCol(4);
111 WindowSizer->AddGrowableCol(5);
112 WindowSizer->AddGrowableCol(6);
113 WindowSizer->SetFlexibleDirection( wxBOTH );
114 WindowSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
116 this->SetSizer(WindowSizer);
117 WindowSizer->Fit(this);
119 this->SetBackgroundColour(wxColour(0,0,0));
123 XCCalendarMonthView::~XCCalendarMonthView(){
129 void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars){
131 // TODO: Delete the old calendar entries.
133 // Add the new calendar entries.
137 for (vector<XCCalendarMonthViewGridDayWeek>::iterator WeekIter = grid->WeekList.begin();
138 WeekIter != grid->WeekList.end(); WeekIter++){
142 for (vector<XCCalendarMonthViewGridDayData>::iterator DayIter = (*WeekIter).DayList.begin();
143 DayIter != (*WeekIter).DayList.end(); DayIter++){
145 // TODO: Add CalendarEntries.
147 XCCalendarDay *CalendarDayItem = new XCCalendarDay(this, "XCCalendarMonthView Test", wxPoint(50, 50), wxSize(200, 200));
149 // Setup the control.
151 CalendarDayItem->SetupControl((*DayIter).Day, (*DayIter).Month, (*DayIter).Year, (*DayIter).IsInMonth, this, calendarStorage, hideAccounts, hideCalendars);
153 CalendarDayList.push_back(CalendarDayItem);
154 WindowSizer->Add(CalendarDayItem, 1, wxEXPAND, 5);
160 // Add the Growable Rows.
162 for (int WeekSeek = 0; WeekSeek < Week; WeekSeek++){
164 WindowSizer->AddGrowableRow((WeekSeek + 1));
170 void XCCalendarMonthView::Repaint(){
178 void XCCalendarMonthView::PaintFrameEvent(wxPaintEvent &PaintEvent){
184 void XCCalendarMonthView::ResizeFrameEvent(wxSizeEvent &SizeEvent){
186 // TODO: Check if window size is less than 120 pixels and if it is,
187 // switch to the small block mode.
189 // Refresh the window.
195 void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &DeselectEvent){
197 for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
198 DayIter != CalendarDayList.end(); DayIter++){
200 if (DeselectEvent.GetClientData() != (void*)(*DayIter)){
202 wxCommandEvent DeselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
203 DeselectEvent.SetId(ID_DESELECTALLITEMS);
204 wxPostEvent((*DayIter), DeselectEvent);
212 void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
214 for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
215 DayIter != CalendarDayList.end(); DayIter++){
217 wxCommandEvent HideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
218 HideEvent.SetInt(accountData.GetInt());
219 HideEvent.SetId(ID_HIDEENTRIES);
220 wxPostEvent((*DayIter), HideEvent);
226 void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
228 for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
229 DayIter != CalendarDayList.end(); DayIter++){
231 wxCommandEvent ShowEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
232 ShowEvent.SetInt(accountData.GetInt());
233 ShowEvent.SetId(ID_SHOWENTRIES);
234 wxPostEvent((*DayIter), ShowEvent);
240 void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
242 for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
243 DayIter != CalendarDayList.end(); DayIter++){
245 wxCommandEvent HideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
246 HideEvent.SetInt(accountData.GetInt());
247 HideEvent.SetId(ID_HIDECALENDARENTRIES);
248 wxPostEvent((*DayIter), HideEvent);
254 void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
256 for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
257 DayIter != CalendarDayList.end(); DayIter++){
259 wxCommandEvent HideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
260 HideEvent.SetInt(accountData.GetInt());
261 HideEvent.SetId(ID_SHOWCALENDARENTRIES);
262 wxPostEvent((*DayIter), HideEvent);