1 // XCCalendarManipulator.cpp - Xestia Calendar XCCalendarManipulator widget class.
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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)
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){
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);
36 // Setup the navigation section.
38 szrNavigation = new wxBoxSizer( wxHORIZONTAL );
39 pnlMain->SetSizer(szrNavigation);
41 // Add next month and previous month buttons.
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);
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));
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);
64 // Setup the static text.
66 dateButton = new wxButton(pnlMain, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
70 test.SetWeight(wxFONTWEIGHT_BOLD);
71 test.SetPointSize(18);
73 dateButton->SetFont(Test);
74 dateButton->SetForegroundColour(wxColour(255,255,255));
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);
83 Connect(ID_CHANGEGRID, XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEventHandler(XCCalendarManipulator::ChangeGrid));
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();
95 // Setup the month selection control.
97 wxDateTime dtNow = wxDateTime::Now();
99 moo = new XCCalendarMonthSelect(this);
100 month = ((int)dtNow.GetMonth() + 1);
101 year = dtNow.GetYear();
102 moo->UpdateDate(month, year);
103 UpdateDateButtonText();
105 // Setup the calendars list.
107 calendarList = new XCCalendarList(this);
109 // Setup the calendar data storage pointer.
111 this->dataStorage = dataStorage;
115 XCCalendarManipulator::~XCCalendarManipulator(){
117 // Destory the controls from the widget.
121 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
123 // Bring up a popup control to select the month and year.
125 moo->SetPosition(wxPoint(dateButton->GetScreenRect().GetLeft(), dateButton->GetScreenRect().GetBottom()));
126 moo->UpdateDate(month, year);
131 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
133 if (month == moo->GetMonth() && year == moo->GetYear()){
137 month = moo->GetMonth();
138 year = moo->GetYear();
140 // Post an event to the parent control to update the grid.
142 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
143 changeGrid.SetId(ID_CHANGEGRID);
144 wxPostEvent(this->GetParent(), changeGrid);
146 UpdateDateButtonText();
150 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
155 // Get the current month and year.
157 newMonth = moo->GetMonth();
158 newYear = moo->GetYear();
170 moo->UpdateDate(month, year);
172 // Post an event to the parent control to update the grid.
174 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
175 changeGrid.SetId(ID_CHANGEGRID);
176 wxPostEvent(this->GetParent(), changeGrid);
178 UpdateDateButtonText();
182 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
187 // Get the current month and year.
189 newMonth = moo->GetMonth();
190 newYear = moo->GetYear();
202 moo->UpdateDate(month, year);
204 // Post an event to the parent control to update the grid.
206 wxCommandEvent changeGrid(XCCALENDARCTRL_CHANGEGRID);
207 changeGrid.SetId(ID_CHANGEGRID);
208 wxPostEvent(this->GetParent(), changeGrid);
210 UpdateDateButtonText();
214 void XCCalendarManipulator::ShowCalendarsList(wxCommandEvent &event){
216 // Update the list of calendars before showing.
218 calendarList->SetPosition(wxPoint(calendarsButton->GetScreenRect().GetLeft(), calendarsButton->GetScreenRect().GetBottom()));
219 calendarList->UpdateCalendarList(dataStorage);
220 calendarList->Popup();
224 void XCCalendarManipulator::UpdateDateButtonText(){
226 // Update the date text.
228 string newDateText = "";
230 switch (moo->GetMonth()){
232 newDateText = _("January");
235 newDateText = _("February");
238 newDateText = _("March");
241 newDateText = _("April");
244 newDateText = _("May");
247 newDateText = _("June");
250 newDateText = _("July");
253 newDateText = _("August");
256 newDateText = _("September");
259 newDateText = _("October");
262 newDateText = _("November");
265 newDateText = _("December");
271 newDateText += to_string(year);
273 dateButton->SetLabel(newDateText);
278 int XCCalendarManipulator::GetMonth(){
284 int XCCalendarManipulator::GetYear(){
290 vector<int> XCCalendarManipulator::GetHiddenAccountsList(){
292 return calendarList->GetHiddenAccountsList();
296 vector<int> XCCalendarManipulator::GetHiddenCalendarsList(){
298 return calendarList->GetHiddenCalendarsList();