Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
svrblist: Implemented server blacklist code for Xestia Address Book
[xestiacalendar/.git] / source / widgets / XCCalendarMonthView.cpp
1 // XCCalendarMonthView.cpp - Xestia Calendar XCCalendarMonthView widget class.
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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"
21 using namespace std;
23 BEGIN_EVENT_TABLE(XCCalendarMonthView, wxPanel)
24 EVT_PAINT(XCCalendarMonthView::PaintFrameEvent)
25 END_EVENT_TABLE()
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){
29         
30         calendarStorage = dataStorage;
31                 
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);
39         
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);
47         
48         ProcessGrid(grid, hideAccounts, hideCalendars);
49         
50         // Setup the days.
51         
52         // Setup the growable rows and columns.
53         
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 );
63         
64         this->SetSizer(WindowSizer);
65         WindowSizer->Fit(this);
66         this->Layout();
67         this->SetBackgroundColour(wxColour(0,0,0));
68         
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));
74         
75 }
77 XCCalendarMonthView::XCCalendarMonthView(XCCalendarMonthViewGrid *grid, CalendarDataStorage *dataStorage, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars)
78         : wxPanel(NULL, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){
79         
80         Connect(ID_MONTHVIEWCLEARSELECTION, XCCALENDARMONTH_DESELECTOTHERENTRIES, wxCommandEventHandler(XCCalendarMonthView::DeselectOthersEvent));
81         
82         calendarStorage = dataStorage;
83                 
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);
91         
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);
99         
100         ProcessGrid(grid, hideAccounts, hideCalendars);
101         
102         // Setup the days.
103         
104         // Setup the growable rows and columns.
105         
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 );
115         
116         this->SetSizer(WindowSizer);
117         WindowSizer->Fit(this);
118         this->Layout();
119         this->SetBackgroundColour(wxColour(0,0,0));
120         
123 XCCalendarMonthView::~XCCalendarMonthView(){
124         
125         
126         
129 void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector<int> *hideAccounts, std::vector<int> *hideCalendars){
130         
131         // TODO: Delete the old calendar entries.
132         
133         // Add the new calendar entries.
134         
135         int Week = 0;
136         
137         for (vector<XCCalendarMonthViewGridDayWeek>::iterator WeekIter = grid->WeekList.begin();
138                 WeekIter != grid->WeekList.end(); WeekIter++){
139                         
140                 Week++;
141                         
142                 for (vector<XCCalendarMonthViewGridDayData>::iterator DayIter = (*WeekIter).DayList.begin();
143                         DayIter != (*WeekIter).DayList.end(); DayIter++){
144                                 
145                         // TODO: Add CalendarEntries.
146                                 
147                         XCCalendarDay *CalendarDayItem = new XCCalendarDay(this, "XCCalendarMonthView Test", wxPoint(50, 50), wxSize(200, 200));
148                                 
149                         // Setup the control.
150                                 
151                         CalendarDayItem->SetupControl((*DayIter).Day, (*DayIter).Month, (*DayIter).Year, (*DayIter).IsInMonth, this, calendarStorage, hideAccounts, hideCalendars);
152                                 
153                         CalendarDayList.push_back(CalendarDayItem);
154                         WindowSizer->Add(CalendarDayItem, 1, wxEXPAND, 5);
155                                 
156                 }
157                         
158         }
159         
160         // Add the Growable Rows.
161         
162         for (int WeekSeek = 0; WeekSeek < Week; WeekSeek++){
163                 
164                 WindowSizer->AddGrowableRow((WeekSeek + 1));
165                 
166         }
167         
170 void XCCalendarMonthView::Repaint(){
171         
172         // Draw the border.
173         
174         this->Layout();
178 void XCCalendarMonthView::PaintFrameEvent(wxPaintEvent &PaintEvent){
180         Repaint();
181         
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.
188         
189         // Refresh the window.
190         
191         this->Refresh();
192         
195 void XCCalendarMonthView::DeselectOthersEvent(wxCommandEvent &DeselectEvent){
196         
197         for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
198                 DayIter != CalendarDayList.end(); DayIter++){
199                         
200                 if (DeselectEvent.GetClientData() != (void*)(*DayIter)){
201                         
202                         wxCommandEvent DeselectEvent(XCCALENDARDAY_DESELECTALLENTRIES);
203                         DeselectEvent.SetId(ID_DESELECTALLITEMS);
204                         wxPostEvent((*DayIter), DeselectEvent);
205                         
206                 }
207                         
208         }
209         
212 void XCCalendarMonthView::HideAccountEntries(wxCommandEvent &accountData){
213         
214         for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
215                 DayIter != CalendarDayList.end(); DayIter++){
216                         
217                 wxCommandEvent HideEvent(XCCALENDARDAY_HIDEACCOUNTENTRIES);
218                 HideEvent.SetInt(accountData.GetInt());
219                 HideEvent.SetId(ID_HIDEENTRIES);
220                 wxPostEvent((*DayIter), HideEvent);
221                         
222         }
223         
226 void XCCalendarMonthView::ShowAccountEntries(wxCommandEvent &accountData){
227         
228         for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
229                 DayIter != CalendarDayList.end(); DayIter++){
230                         
231                 wxCommandEvent ShowEvent(XCCALENDARDAY_SHOWACCOUNTENTRIES);
232                 ShowEvent.SetInt(accountData.GetInt());
233                 ShowEvent.SetId(ID_SHOWENTRIES);
234                 wxPostEvent((*DayIter), ShowEvent);
235                         
236         }
237         
240 void XCCalendarMonthView::HideCalendarEntries(wxCommandEvent &accountData){
241         
242         for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
243                 DayIter != CalendarDayList.end(); DayIter++){
244                         
245                 wxCommandEvent HideEvent(XCCALENDARDAY_HIDECALENDARENTRIES);
246                 HideEvent.SetInt(accountData.GetInt());
247                 HideEvent.SetId(ID_HIDECALENDARENTRIES);
248                 wxPostEvent((*DayIter), HideEvent);
249                         
250         }
251         
254 void XCCalendarMonthView::ShowCalendarEntries(wxCommandEvent &accountData){
255         
256         for (vector<XCCalendarDay*>::iterator DayIter = CalendarDayList.begin();
257                 DayIter != CalendarDayList.end(); DayIter++){
258                         
259                 wxCommandEvent HideEvent(XCCALENDARDAY_SHOWCALENDARENTRIES);
260                 HideEvent.SetInt(accountData.GetInt());
261                 HideEvent.SetId(ID_SHOWCALENDARENTRIES);
262                 wxPostEvent((*DayIter), HideEvent);
263                         
264         }
265         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy