Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
XCCalendarManipulator: Set button background colours to the main panel background...
[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         previousButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
62         nextButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
63         calendarsButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
64                 
65         // Setup the static text.
66                 
67         dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
68                 
69         wxFont test;
70         
71         test.SetWeight(wxFONTWEIGHT_BOLD);
72         test.SetPointSize(18);
73                 
74         dateButton->SetFont(test);
75         dateButton->SetForegroundColour(wxColour(255,255,255));
76         dateButton->SetBackgroundColour(pnlMain->GetBackgroundColour());
77         
78         // Setup the manipulator control.
80         szrNavigation->Add(previousButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
81         szrNavigation->Add(calendarsButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
82         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
83         szrNavigation->Add(dateButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
84         szrNavigation->Add( 0, 0, 1, wxEXPAND, 5 );
85         szrNavigation->Add(nextButton, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
86         szrNavigation->Layout();
87                 
88         // Setup the month selection control.
89         
90         wxDateTime dtNow = wxDateTime::Now();
91         
92         moo = new XCCalendarMonthSelect(this);
93         month = ((int)dtNow.GetMonth() + 1);
94         year = dtNow.GetYear();
95         moo->UpdateDate(month, year);
96         UpdateDateButtonText();
97         
98         // Setup the calendars list.
99         
100         calendarList = new XCCalendarList(this);
101         
102         // Setup the calendar data storage pointer.
103         
104         this->dataStorage = dataStorage;
105                 
106         // Setup the event controls.
108         dateButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this);
109         nextButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this);
110         calendarsButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this);
111         previousButton->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this);
112         
113         Bind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID);
116 XCCalendarManipulator::~XCCalendarManipulator(){
117         
118         // Destory the controls from the widget.
119         
122 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
123         
124         // Bring up a popup control to select the month and year.
125         
126         moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
127         moo->UpdateDate(month, year);
128         moo->Popup();
129         
132 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
133         
134         if (month == moo->GetMonth() && year == moo->GetYear()){
135                 return;
136         }
137         
138         month = moo->GetMonth();
139         year = moo->GetYear();
140         
141         // Post an event to the parent control to update the grid.
142         
143         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
144         changeGrid.SetId(ID_CHANGEGRID);
145         wxPostEvent(this->GetParent(), changeGrid);
146         
147         UpdateDateButtonText();
148         
151 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
152         
153         int newMonth = 1;
154         int newYear = 0;
155         
156         // Get the current month and year.
157         
158         newMonth = moo->GetMonth();
159         newYear = moo->GetYear();
161         if (newMonth == 12){
162                 newMonth = 1;
163                 newYear++;
164         } else {
165                 newMonth++;
166         }
167         
168         month = newMonth;
169         year = newYear;
171         moo->UpdateDate(month, year);
172         
173         // Post an event to the parent control to update the grid.
174         
175         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
176         changeGrid.SetId(ID_CHANGEGRID);
177         wxPostEvent(this->GetParent(), changeGrid);
179         UpdateDateButtonText();
180         
183 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
184         
185         int newMonth = 1;
186         int newYear = 0;
187         
188         // Get the current month and year.
189         
190         newMonth = moo->GetMonth();
191         newYear = moo->GetYear();
193         if (newMonth == 1){
194                 newMonth = 12;
195                 newYear--;
196         } else {
197                 newMonth--;
198         }
200         month = newMonth;
201         year = newYear;
202         
203         moo->UpdateDate(month, year);
204         
205         // Post an event to the parent control to update the grid.
206         
207         wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
208         changeGrid.SetId(ID_CHANGEGRID);
209         wxPostEvent(this->GetParent(), changeGrid);
210         
211         UpdateDateButtonText();
212         
215 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
216         
217         // Update the list of calendars before showing.
218         
219         calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
220         calendarList->UpdateCalendarList(dataStorage);
221         calendarList->Popup();
222         
225 void XCCalendarManipulator::UpdateDateButtonText(){
226         
227         // Update the date text.
228         
229         string newDateText = "";
230         
231         switch (moo->GetMonth()){
232                 case 1:
233                         newDateText = _("January");
234                         break;
235                 case 2:
236                         newDateText = _("February");
237                         break;
238                 case 3:
239                         newDateText = _("March");
240                         break;
241                 case 4:
242                         newDateText = _("April");
243                         break;
244                 case 5:
245                         newDateText = _("May");
246                         break;
247                 case 6:
248                         newDateText = _("June");
249                         break;
250                 case 7:
251                         newDateText = _("July");
252                         break;
253                 case 8:
254                         newDateText = _("August");
255                         break;
256                 case 9:
257                         newDateText = _("September");
258                         break;
259                 case 10:
260                         newDateText = _("October");
261                         break;
262                 case 11:
263                         newDateText = _("November");
264                         break;
265                 case 12:
266                         newDateText = _("December");
267                         break;
268         }
269         
270         newDateText += " ";
271         
272         newDateText += to_string(year);
273         
274         dateButton->SetLabel(newDateText);
275         szrMain->Layout();
276         
279 int XCCalendarManipulator::GetMonth(){
280         
281         return month;
282         
285 int XCCalendarManipulator::GetYear(){
286         
287         return year;
288         
291 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
292         
293         return calendarList->GetHiddenAccountsList();
294         
297 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
298         
299         return calendarList->GetHiddenCalendarsList();
300         
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