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, const wxPoint& pos, const wxSize& size)
27 : wxPanel(parent, wxID_ANY, pos, size, wxTAB_TRAVERSAL, title){
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);
35 // Setup the navigation section.
37 szrNavigation = new wxBoxSizer( wxHORIZONTAL );
38 pnlMain->SetSizer(szrNavigation);
40 // Add next month and previous month buttons.
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);
45 wxMemoryInputStream PreviousIcon(icons_previous_png, sizeof(icons_previous_png));
46 wxMemoryInputStream NextIcon(icons_next_png, sizeof(icons_next_png));
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);
54 PreviousButton->SetBitmap(PreviousIconBitmap);
55 NextButton->SetBitmap(NextIconBitmap);
57 // Setup the static text.
59 DateButton = new wxButton(pnlMain, wxID_ANY, _("November 2016"), wxDefaultPosition, wxDefaultSize, 0|wxNO_BORDER);
63 Test.SetWeight(wxFONTWEIGHT_BOLD);
64 Test.SetPointSize(18);
66 DateButton->SetFont(Test);
67 DateButton->SetForegroundColour(wxColour(255,255,255));
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);
75 Connect(wxID_ANY, XCCALENDARMANIPULATOR_CHANGEGRID, wxCommandEventHandler(XCCalendarManipulator::ChangeGrid));
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();
86 // Setup the month selection control.
88 wxDateTime DTNow = wxDateTime::Now();
90 Moo = new XCCalendarMonthSelect(this);
91 Month = ((int)DTNow.GetMonth() + 1);
92 Year = DTNow.GetYear();
93 Moo->UpdateDate(Month, Year);
97 XCCalendarManipulator::~XCCalendarManipulator(){
99 // Destory the controls from the widget.
103 void XCCalendarManipulator::DateTextClick(wxCommandEvent &event){
105 // Bring up a popup control to select the month and year.
107 Moo->SetPosition(wxPoint(DateButton->GetScreenRect().GetLeft(), DateButton->GetScreenRect().GetBottom()));
108 Moo->UpdateDate(Month, Year);
113 void XCCalendarManipulator::ChangeGrid(wxCommandEvent &event){
115 if (Month == Moo->GetMonth() && Year == Moo->GetYear()){
119 Month = Moo->GetMonth();
120 Year = Moo->GetYear();
122 // Post an event to the parent control to update the grid.
124 wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
125 wxPostEvent(this->GetParent(), ChangeGrid);
127 UpdateDateButtonText();
131 void XCCalendarManipulator::NextMonth(wxCommandEvent &event){
136 // Get the current month and year.
138 NewMonth = Moo->GetMonth();
139 NewYear = Moo->GetYear();
151 Moo->UpdateDate(Month, Year);
153 // Post an event to the parent control to update the grid.
155 wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
156 wxPostEvent(this->GetParent(), ChangeGrid);
158 UpdateDateButtonText();
162 void XCCalendarManipulator::PreviousMonth(wxCommandEvent &event){
167 // Get the current month and year.
169 NewMonth = Moo->GetMonth();
170 NewYear = Moo->GetYear();
182 Moo->UpdateDate(Month, Year);
184 // Post an event to the parent control to update the grid.
186 wxCommandEvent ChangeGrid(XCCALENDARCTRL_CHANGEGRID);
187 wxPostEvent(this->GetParent(), ChangeGrid);
189 UpdateDateButtonText();
193 void XCCalendarManipulator::UpdateDateButtonText(){
195 // Update the date text.
197 string NewDateText = "";
199 switch (Moo->GetMonth()){
201 NewDateText = _("January");
204 NewDateText = _("February");
207 NewDateText = _("March");
210 NewDateText = _("April");
213 NewDateText = _("May");
216 NewDateText = _("June");
219 NewDateText = _("July");
222 NewDateText = _("August");
225 NewDateText = _("September");
228 NewDateText = _("October");
231 NewDateText = _("November");
234 NewDateText = _("December");
240 NewDateText += to_string(Year);
242 DateButton->SetLabel(NewDateText);
247 int XCCalendarManipulator::GetMonth(){
253 int XCCalendarManipulator::GetYear(){