Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
camelCase: Converted remaining code that was missed
[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