Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmMain: Implemented code to hide/show calendar entries
[xestiacalendar/.git] / source / widgets / XCCalendarManipulator.cpp
1 // XCCalendarManipulator.cpp - Xestia Calendar XCCalendarManipulator 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 "XCCalendarManipulator.h"
21 BEGIN_EVENT_TABLE(XCCalendarManipulator, wxPanel)
22 END_EVENT_TABLE()
24 using namespace std;
26 XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& title, 
27         const wxPoint& pos, const wxSize& size, CalendarDataStorage *dataStorage)
28         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
29         
30         szrMain = new wxBoxSizer( wxVERTICAL );
31         pnlMain = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(500, 50), wxTAB_TRAVERSAL);
32         pnlMain->SetBackgroundColour(wxColour(40,40,40));
33         this->SetSizer(szrMain);
34         szrMain->Add(pnlMain, 0, wxEXPAND, 0);
35         
36         // Setup the navigation section.
37                 
38         szrNavigation = new wxBoxSizer( wxHORIZONTAL );
39         pnlMain->SetSizer(szrNavigation);
40                 
41         // Add next month and previous month buttons.
42                 
43         PreviousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
44         NextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
45         CalendarsButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
46         
47         wxMemoryInputStream PreviousIcon(icons_previous_png, sizeof(icons_previous_png));
48         wxMemoryInputStream NextIcon(icons_next_png, sizeof(icons_next_png));
49         wxMemoryInputStream CalendarsIcon(icons_calendars_png, sizeof(icons_calendars_png));
50                 
51         wxImage icons_previous_png(PreviousIcon, wxBITMAP_TYPE_PNG);
52         PreviousIconBitmap = wxBitmap(icons_previous_png, -1);
54         wxImage icons_next_png(NextIcon, wxBITMAP_TYPE_PNG);
55         NextIconBitmap = wxBitmap(icons_next_png, -1);
57         wxImage icons_calendars_png(CalendarsIcon, wxBITMAP_TYPE_PNG);
58         CalendarsIconBitmap = wxBitmap(icons_calendars_png, -1);
60         PreviousButton->SetBitmap(PreviousIconBitmap);
61         NextButton->SetBitmap(NextIconBitmap);
62         CalendarsButton->SetBitmap(CalendarsIconBitmap);
63                 
64         // Setup the static text.
65                 
66         DateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
67                 
68         wxFont Test;
69         
70         Test.SetWeight(wxFONTWEIGHT_BOLD);
71         Test.SetPointSize(18);
72                 
73         DateButton->SetFont(Test);
74         DateButton->SetForegroundColour(wxColour(255,255,255));
75         
76         // Setup the event controls.
78         DateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
79         NextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
80         CalendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
81         PreviousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
82         
83         Connect(ID_CHANGEGRID, XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEventHandler(XCCalendarManipulator::ChangeGrid));
84         
85         // Setup the manipulator control.
87         szrNavigation->Add(PreviousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
88         szrNavigation->Add(CalendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
89         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
90         szrNavigation->Add(DateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
91         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
92         szrNavigation->Add(NextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
93         szrNavigation->Layout();
94                 
95         // Setup the month selection control.
96         
97         wxDateTime DTNow = wxDateTime::Now();
98         
99         Moo = new XCCalendarMonthSelect(this);
100         Month = ((int)DTNow.GetMonth() + 1);
101         Year = DTNow.GetYear();
102         Moo->UpdateDate(Month, Year);
103         UpdateDateButtonText();
104         
105         // Setup the calendars list.
106         
107         calendarList = new XCCalendarList(this);
108         
109         // Setup the calendar data storage pointer.
110         
111         this->dataStorage = dataStorage;
112                 
115 XCCalendarManipulator::~XCCalendarManipulator(){
116         
117         // Destory the controls from the widget.
118         
121 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
122         
123         // Bring up a popup control to select the month and year.
124         
125         Moo->SetPosition(wxPoint(DateButton->GetScreenRect().GetLeft(), DateButton->GetScreenRect().GetBottom()));
126         Moo->UpdateDate(Month, Year);
127         Moo->Popup();
128         
131 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
132         
133         if (Month == Moo->GetMonth() && Year == Moo->GetYear()){
134                 return;
135         }
136         
137         Month = Moo->GetMonth();
138         Year = Moo->GetYear();
139         
140         // Post an event to the parent control to update the grid.
141         
142         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
143         ChangeGrid.SetId(ID_CHANGEGRID);
144         wxPostEvent(this->GetParent(), ChangeGrid);
145         
146         UpdateDateButtonText();
147         
150 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
151         
152         int NewMonth = 1;
153         int NewYear = 0;
154         
155         // Get the current month and year.
156         
157         NewMonth = Moo->GetMonth();
158         NewYear = Moo->GetYear();
160         if (NewMonth == 12){
161                 NewMonth = 1;
162                 NewYear++;
163         } else {
164                 NewMonth++;
165         }
166         
167         Month = NewMonth;
168         Year = NewYear;
170         Moo->UpdateDate(Month, Year);
171         
172         // Post an event to the parent control to update the grid.
173         
174         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
175         ChangeGrid.SetId(ID_CHANGEGRID);
176         wxPostEvent(this->GetParent(), ChangeGrid);
178         UpdateDateButtonText();
179         
182 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
183         
184         int NewMonth = 1;
185         int NewYear = 0;
186         
187         // Get the current month and year.
188         
189         NewMonth = Moo->GetMonth();
190         NewYear = Moo->GetYear();
192         if (NewMonth == 1){
193                 NewMonth = 12;
194                 NewYear--;
195         } else {
196                 NewMonth--;
197         }
199         Month = NewMonth;
200         Year = NewYear;
201         
202         Moo->UpdateDate(Month, Year);
203         
204         // Post an event to the parent control to update the grid.
205         
206         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
207         ChangeGrid.SetId(ID_CHANGEGRID);
208         wxPostEvent(this->GetParent(), ChangeGrid);
209         
210         UpdateDateButtonText();
211         
214 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
215         
216         // Update the list of calendars before showing.
217         
218         calendarList->SetPosition(wxPoint(CalendarsButton->GetScreenRect().GetLeft(), CalendarsButton->GetScreenRect().GetBottom()));
219         calendarList->UpdateCalendarList(dataStorage);
220         calendarList->Popup();
221         
224 void XCCalendarManipulator::UpdateDateButtonText(){
225         
226         // Update the date text.
227         
228         string NewDateText = "";
229         
230         switch (Moo->GetMonth()){
231                 case 1:
232                         NewDateText = _("January");
233                         break;
234                 case 2:
235                         NewDateText = _("February");
236                         break;
237                 case 3:
238                         NewDateText = _("March");
239                         break;
240                 case 4:
241                         NewDateText = _("April");
242                         break;
243                 case 5:
244                         NewDateText = _("May");
245                         break;
246                 case 6:
247                         NewDateText = _("June");
248                         break;
249                 case 7:
250                         NewDateText = _("July");
251                         break;
252                 case 8:
253                         NewDateText = _("August");
254                         break;
255                 case 9:
256                         NewDateText = _("September");
257                         break;
258                 case 10:
259                         NewDateText = _("October");
260                         break;
261                 case 11:
262                         NewDateText = _("November");
263                         break;
264                 case 12:
265                         NewDateText = _("December");
266                         break;
267         }
268         
269         NewDateText += " ";
270         
271         NewDateText += to_string(Year);
272         
273         DateButton->SetLabel(NewDateText);
274         szrMain->Layout();
275         
278 int XCCalendarManipulator::GetMonth(){
279         
280         return Month;
281         
284 int XCCalendarManipulator::GetYear(){
285         
286         return Year;
287         
290 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
291         
292         return calendarList->GetHiddenAccountsList();
293         
296 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
297         
298         return calendarList->GetHiddenCalendarsList();
299         
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