Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Updated and added 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, const wxPoint& pos, const wxSize& size)
27         : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
28         
29         szrMain = new wxBoxSizer( wxVERTICAL );
30         pnlMain = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(500, 50), wxTAB_TRAVERSAL);
31         pnlMain->SetBackgroundColour(wxColour(40,40,40));
32         this->SetSizer(szrMain);
33         szrMain->Add(pnlMain, 0, wxEXPAND, 0);
34                 
35         // Setup the navigation section.
36                 
37         szrNavigation = new wxBoxSizer( wxHORIZONTAL );
38         pnlMain->SetSizer(szrNavigation);
39                 
40         // Add next month and previous month buttons.
41                 
42         PreviousButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(32,32), 0|wxNO_BORDER);
43         NextButton = 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                 
48         wxImage icons_previous_png(PreviousIcon, wxBITMAP_TYPE_PNG);
49         PreviousIconBitmap = wxBitmap(icons_previous_png, -1);
51         wxImage icons_next_png(NextIcon, wxBITMAP_TYPE_PNG);
52         NextIconBitmap = wxBitmap(icons_next_png, -1);
53                 
54         PreviousButton->SetBitmap(PreviousIconBitmap);
55         NextButton->SetBitmap(NextIconBitmap);
56                 
57         // Setup the static text.
58                 
59         DateButton = new wxButton(pnlMain, wxID_ANY, _("November 2016"), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
60                 
61         wxFont Test;
62         
63         Test.SetWeight(wxFONTWEIGHT_BOLD);
64         Test.SetPointSize(18);
65                 
66         DateButton->SetFont(Test);
67         DateButton->SetForegroundColour(wxColour(255,255,255));
68         
69         // Setup the event controls.
71         DateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
72         NextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
73         PreviousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
74         
75         Connect(wxID_ANY, XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEventHandler(XCCalendarManipulator::ChangeGrid));
76         
77         // Setup the manipulator control.
79         szrNavigation->Add(PreviousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
80         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
81         szrNavigation->Add(DateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
82         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
83         szrNavigation->Add(NextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
84         szrNavigation->Layout();
85                 
86         // Setup the month selection control.
87         
88         wxDateTime DTNow = wxDateTime::Now();
89         
90         Moo = new XCCalendarMonthSelect(this);
91         Month = ((int)DTNow.GetMonth() + 1);
92         Year = DTNow.GetYear();
93         Moo->UpdateDate(Month, Year);
94                 
95 }
97 XCCalendarManipulator::~XCCalendarManipulator(){
98         
99         // Destory the controls from the widget.
100         
103 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
104         
105         // Bring up a popup control to select the month and year.
106         
107         Moo->SetPosition(wxPoint(DateButton->GetScreenRect().GetLeft(), DateButton->GetScreenRect().GetBottom()));
108         Moo->UpdateDate(Month, Year);
109         Moo->Popup();
110         
113 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
114         
115         if (Month == Moo->GetMonth() && Year == Moo->GetYear()){
116                 return;
117         }
118         
119         Month = Moo->GetMonth();
120         Year = Moo->GetYear();
121         
122         // Post an event to the parent control to update the grid.
123         
124         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
125         wxPostEvent(this->GetParent(), ChangeGrid);
126         
127         UpdateDateButtonText();
128         
131 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
132         
133         int NewMonth = 1;
134         int NewYear = 0;
135         
136         // Get the current month and year.
137         
138         NewMonth = Moo->GetMonth();
139         NewYear = Moo->GetYear();
141         if (NewMonth == 12){
142                 NewMonth = 1;
143                 NewYear++;
144         } else {
145                 NewMonth++;
146         }
147         
148         Month = NewMonth;
149         Year = NewYear;
151         Moo->UpdateDate(Month, Year);
152         
153         // Post an event to the parent control to update the grid.
154         
155         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
156         wxPostEvent(this->GetParent(), ChangeGrid);
158         UpdateDateButtonText();
159         
162 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
163         
164         int NewMonth = 1;
165         int NewYear = 0;
166         
167         // Get the current month and year.
168         
169         NewMonth = Moo->GetMonth();
170         NewYear = Moo->GetYear();
172         if (NewMonth == 1){
173                 NewMonth = 12;
174                 NewYear--;
175         } else {
176                 NewMonth--;
177         }
179         Month = NewMonth;
180         Year = NewYear;
181         
182         Moo->UpdateDate(Month, Year);
183         
184         // Post an event to the parent control to update the grid.
185         
186         wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
187         wxPostEvent(this->GetParent(), ChangeGrid);
188         
189         UpdateDateButtonText();
190         
193 void XCCalendarManipulator::UpdateDateButtonText(){
194         
195         // Update the date text.
196         
197         string NewDateText = "";
198         
199         switch (Moo->GetMonth()){
200                 case 1:
201                         NewDateText = _("January");
202                         break;
203                 case 2:
204                         NewDateText = _("February");
205                         break;
206                 case 3:
207                         NewDateText = _("March");
208                         break;
209                 case 4:
210                         NewDateText = _("April");
211                         break;
212                 case 5:
213                         NewDateText = _("May");
214                         break;
215                 case 6:
216                         NewDateText = _("June");
217                         break;
218                 case 7:
219                         NewDateText = _("July");
220                         break;
221                 case 8:
222                         NewDateText = _("August");
223                         break;
224                 case 9:
225                         NewDateText = _("September");
226                         break;
227                 case 10:
228                         NewDateText = _("October");
229                         break;
230                 case 11:
231                         NewDateText = _("November");
232                         break;
233                 case 12:
234                         NewDateText = _("December");
235                         break;
236         }
237         
238         NewDateText += " ";
239         
240         NewDateText += to_string(Year);
241         
242         DateButton->SetLabel(NewDateText);
243         szrMain->Layout();
244         
247 int XCCalendarManipulator::GetMonth(){
248         
249         return Month;
250         
253 int XCCalendarManipulator::GetYear(){
254         
255         return Year;
256         
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