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();