Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
random: Implemented Win32 version
[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 wxDEFINE_EVENT(XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEvent);
23 using namespace std;
25 XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& title, 
26         const wxPoint& pos, const wxSize& size, CalendarDataStorage *dataStorage)
27         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
28         szrMain = new wxBoxSizer( wxVERTICAL );
29         pnlMain = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(500, 50), wxTAB_TRAVERSAL);
30         pnlMain->SetBackgroundColour(wxColour(40,40,40));
31         this->SetSizer(szrMain);
32         szrMain->Add(pnlMain, 0, wxEXPAND, 0);
33         
34         // Setup the navigation section.
35                 
36         szrNavigation = new wxBoxSizer( wxHORIZONTAL );
37         pnlMain->SetSizer(szrNavigation);
38                 
39         // Add next month and previous month buttons.
40                 
41         previousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
42         nextButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
43         calendarsButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
44         
45         wxMemoryInputStream previousIcon(icons_previous_png, sizeof(icons_previous_png));
46         wxMemoryInputStream nextIcon(icons_next_png, sizeof(icons_next_png));
47         wxMemoryInputStream calendarsIcon(icons_calendars_png, sizeof(icons_calendars_png));
48                 
49         wxImage icons_previous_png(previousIcon, wxBITMAP_TYPE_PNG);
50         previousIconBitmap = wxBitmap(icons_previous_png, -1);
52         wxImage icons_next_png(nextIcon, wxBITMAP_TYPE_PNG);
53         nextIconBitmap = wxBitmap(icons_next_png, -1);
55         wxImage icons_calendars_png(calendarsIcon, wxBITMAP_TYPE_PNG);
56         calendarsIconBitmap = wxBitmap(icons_calendars_png, -1);
58         previousButton->SetBitmap(previousIconBitmap);
59         nextButton->SetBitmap(nextIconBitmap);
60         calendarsButton->SetBitmap(calendarsIconBitmap);
61                 
62         // Setup the static text.
63                 
64         dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
65                 
66         wxFont test;
67         
68         test.SetWeight(wxFONTWEIGHT_BOLD);
69         test.SetPointSize(18);
70                 
71         dateButton->SetFont(test);
72         dateButton->SetForegroundColour(wxColour(255,255,255));
73         
74         // Setup the manipulator control.
76         szrNavigation->Add(previousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
77         szrNavigation->Add(calendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
78         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
79         szrNavigation->Add(dateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
80         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
81         szrNavigation->Add(nextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
82         szrNavigation->Layout();
83                 
84         // Setup the month selection control.
85         
86         wxDateTime dtNow = wxDateTime::Now();
87         
88         moo = new XCCalendarMonthSelect(this);
89         month = ((int)dtNow.GetMonth() + 1);
90         year = dtNow.GetYear();
91         moo->UpdateDate(month, year);
92         UpdateDateButtonText();
93         
94         // Setup the calendars list.
95         
96         calendarList = new XCCalendarList(this);
97         
98         // Setup the calendar data storage pointer.
99         
100         this->dataStorage = dataStorage;
101                 
102         // Setup the event controls.
104         dateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
105         nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
106         calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
107         previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
108         
109         Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
112 XCCalendarManipulator::~XCCalendarManipulator(){
113         
114         // Destory the controls from the widget.
115         
118 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
119         
120         // Bring up a popup control to select the month and year.
121         
122         moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
123         moo->UpdateDate(month, year);
124         moo->Popup();
125         
128 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
129         
130         if (month == moo->GetMonth() && year == moo->GetYear()){
131                 return;
132         }
133         
134         month = moo->GetMonth();
135         year = moo->GetYear();
136         
137         // Post an event to the parent control to update the grid.
138         
139         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
140         changeGrid.SetId(ID_CHANGEGRID);
141         wxPostEvent(this->GetParent(), changeGrid);
142         
143         UpdateDateButtonText();
144         
147 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
148         
149         int newMonth = 1;
150         int newYear = 0;
151         
152         // Get the current month and year.
153         
154         newMonth = moo->GetMonth();
155         newYear = moo->GetYear();
157         if (newMonth == 12){
158                 newMonth = 1;
159                 newYear++;
160         } else {
161                 newMonth++;
162         }
163         
164         month = newMonth;
165         year = newYear;
167         moo->UpdateDate(month, year);
168         
169         // Post an event to the parent control to update the grid.
170         
171         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
172         changeGrid.SetId(ID_CHANGEGRID);
173         wxPostEvent(this->GetParent(), changeGrid);
175         UpdateDateButtonText();
176         
179 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
180         
181         int newMonth = 1;
182         int newYear = 0;
183         
184         // Get the current month and year.
185         
186         newMonth = moo->GetMonth();
187         newYear = moo->GetYear();
189         if (newMonth == 1){
190                 newMonth = 12;
191                 newYear--;
192         } else {
193                 newMonth--;
194         }
196         month = newMonth;
197         year = newYear;
198         
199         moo->UpdateDate(month, year);
200         
201         // Post an event to the parent control to update the grid.
202         
203         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
204         changeGrid.SetId(ID_CHANGEGRID);
205         wxPostEvent(this->GetParent(), changeGrid);
206         
207         UpdateDateButtonText();
208         
211 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
212         
213         // Update the list of calendars before showing.
214         
215         calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
216         calendarList->UpdateCalendarList(dataStorage);
217         calendarList->Popup();
218         
221 void XCCalendarManipulator::UpdateDateButtonText(){
222         
223         // Update the date text.
224         
225         string newDateText = "";
226         
227         switch (moo->GetMonth()){
228                 case 1:
229                         newDateText = _("January");
230                         break;
231                 case 2:
232                         newDateText = _("February");
233                         break;
234                 case 3:
235                         newDateText = _("March");
236                         break;
237                 case 4:
238                         newDateText = _("April");
239                         break;
240                 case 5:
241                         newDateText = _("May");
242                         break;
243                 case 6:
244                         newDateText = _("June");
245                         break;
246                 case 7:
247                         newDateText = _("July");
248                         break;
249                 case 8:
250                         newDateText = _("August");
251                         break;
252                 case 9:
253                         newDateText = _("September");
254                         break;
255                 case 10:
256                         newDateText = _("October");
257                         break;
258                 case 11:
259                         newDateText = _("November");
260                         break;
261                 case 12:
262                         newDateText = _("December");
263                         break;
264         }
265         
266         newDateText += " ";
267         
268         newDateText += to_string(year);
269         
270         dateButton->SetLabel(newDateText);
271         szrMain->Layout();
272         
275 int XCCalendarManipulator::GetMonth(){
276         
277         return month;
278         
281 int XCCalendarManipulator::GetYear(){
282         
283         return year;
284         
287 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
288         
289         return calendarList->GetHiddenAccountsList();
290         
293 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
294         
295         return calendarList->GetHiddenCalendarsList();
296         
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