// XCCalendarMonthSelect.cpp - Xestia Calendar XCCalendarMonthSelect widget class. // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Address Book is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Address Book is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "XCCalendarMonthSelect.h" XCCalendarMonthSelect::XCCalendarMonthSelect(wxWindow *parent) : wxPopupTransientWindow (parent){ // Setup the main sizer. szrMain = new wxBoxSizer( wxHORIZONTAL ); this->SetSizer(szrMain); this->SetSize(wxSize(255, 40)); // Setup the month selection control. cmbMonth = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); cmbMonth->Append(_("January")); cmbMonth->Append(_("February")); cmbMonth->Append(_("March")); cmbMonth->Append(_("April")); cmbMonth->Append(_("May")); cmbMonth->Append(_("June")); cmbMonth->Append(_("July")); cmbMonth->Append(_("August")); cmbMonth->Append(_("September")); cmbMonth->Append(_("October")); cmbMonth->Append(_("November")); cmbMonth->Append(_("December")); szrMain->Add(cmbMonth, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); // Setup the year selection control. spcYear = new wxSpinCtrl(this, wxID_ANY, _(""), wxDefaultPosition, wxSize(50,-1), wxSP_ARROW_KEYS, 0, 9999, 2016); szrMain->Add(spcYear, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); // Setup the Change button. btnChange = new wxButton(this, wxID_ANY, _("Change"), wxDefaultPosition, wxDefaultSize); szrMain->Add(btnChange, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); // Setup the events. btnChange->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarMonthSelect::UpdateMonthView), NULL, this); this->Layout(); } XCCalendarMonthSelect::~XCCalendarMonthSelect(){ szrMain->Clear(); delete cmbMonth; cmbMonth = nullptr; delete spcYear; spcYear = nullptr; btnChange->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarMonthSelect::UpdateMonthView), NULL, this); delete btnChange; btnChange = nullptr; this->SetSizer(nullptr, true); } void XCCalendarMonthSelect::UpdateDate(int Month, int Year){ cmbMonth->SetSelection((Month - 1)); spcYear->SetValue(Year); } void XCCalendarMonthSelect::UpdateMonthView(wxCommandEvent &event){ // Post an event back to the parent updating the calendar // with the new month. this->Dismiss(); wxCommandEvent UpdateGrid(XCCALENDARMANIPULATOR_CHANGEGRID); UpdateGrid.SetId(ID_CHANGEGRID); wxPostEvent(this->GetParent(), UpdateGrid); } int XCCalendarMonthSelect::GetMonth(){ return (cmbMonth->GetSelection() + 1); } int XCCalendarMonthSelect::GetYear(){ return spcYear->GetValue(); }