Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated widgets
[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(wxID_ANY, 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         wxPostEvent(this->GetParent(), ChangeGrid);
144         
145         UpdateDateButtonText();
146         
149 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
150         
151         int NewMonth = 1;
152         int NewYear = 0;
153         
154         // Get the current month and year.
155         
156         NewMonth = Moo->GetMonth();
157         NewYear = Moo->GetYear();
159         if (NewMonth == 12){
160                 NewMonth = 1;
161                 NewYear++;
162         } else {
163                 NewMonth++;
164         }
165         
166         Month = NewMonth;
167         Year = NewYear;
169         Moo->UpdateDate(Month, Year);
170         
171         // Post an event to the parent control to update the grid.
172         
173         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
174         wxPostEvent(this->GetParent(), ChangeGrid);
176         UpdateDateButtonText();
177         
180 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
181         
182         int NewMonth = 1;
183         int NewYear = 0;
184         
185         // Get the current month and year.
186         
187         NewMonth = Moo->GetMonth();
188         NewYear = Moo->GetYear();
190         if (NewMonth == 1){
191                 NewMonth = 12;
192                 NewYear--;
193         } else {
194                 NewMonth--;
195         }
197         Month = NewMonth;
198         Year = NewYear;
199         
200         Moo->UpdateDate(Month, Year);
201         
202         // Post an event to the parent control to update the grid.
203         
204         wxCommandEvent ChangeGrid(XCCALENDARCTRL_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         
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