// XCCalendarListCalendarCtrl.cpp - XCCalendarListCalendarCtrl class // // (c) 2016 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Calendar 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 Calendar 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 "XCCalendarListCalendarCtrl.h" using namespace std; XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string calendarName, Colour calendarColour) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){ // Create the sizer. szrMain = new wxBoxSizer( wxHORIZONTAL ); this->SetSizer(szrMain); // Setup the checkbox. chkShowCalendar = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, ""); // Setup the label. lblCalendarName = new wxStaticText(this, wxID_ANY, wxString(calendarName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, ""); // Setup the colour. pnlColour = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(16,16), 0, ""); pnlColour->SetBackgroundColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue, calendarColour.alpha)); // Setup the popup menu. calendarMenu = new XCCalendarMenu(); calendarMenu->SetWindowPointer(this); calendarMenu->SetPopupPointer((wxPopupTransientWindow*)this->GetParent()); // Connect them to the sizer. szrMain->Add(15, 0, 0, 0, 5); szrMain->Add(chkShowCalendar, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); szrMain->Add(lblCalendarName, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5); szrMain->Add(pnlColour, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); // Connect the events to the controls. chkShowCalendar->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this); chkShowCalendar->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); lblCalendarName->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); pnlColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); chkShowCalendar->SetValue(wxCHK_CHECKED); } XCCalendarListCalendarCtrl::~XCCalendarListCalendarCtrl(){ // Delete the controls. chkShowCalendar->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this); chkShowCalendar->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); lblCalendarName->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); pnlColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); szrMain->Clear(); delete chkShowCalendar; chkShowCalendar = nullptr; delete lblCalendarName; lblCalendarName = nullptr; delete imgCalendarIcon; imgCalendarIcon = nullptr; delete calendarMenu; calendarMenu = nullptr; delete pnlColour; pnlColour = nullptr; this->SetSizer(nullptr, true); } wxCheckBoxState XCCalendarListCalendarCtrl::GetShowCheckboxState(){ return chkShowCalendar->Get3StateValue(); } int XCCalendarListCalendarCtrl::GetCalendarID(){ return calendarID; } void XCCalendarListCalendarCtrl::SetCalendarID(int calendarID){ this->calendarID = calendarID; calendarMenu->SetCalendarID(this->calendarID); } void XCCalendarListCalendarCtrl::SetAccountPreferencesID(int accountPreferencesID){ this->accountPreferencesID = accountPreferencesID; calendarMenu->SetAccountPreferencesID(this->accountPreferencesID); } void XCCalendarListCalendarCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){ if (chkShowCalendar->Get3StateValue() == wxCHK_CHECKED){ wxCommandEvent event(XCCALENDARCTRL_SHOWCALENDARENTRIES); event.SetInt(calendarID); event.SetId(ID_SHOWCALENDARENTRIES); wxPostEvent(this->GetParent()->GetParent()->GetParent(), event); } else { wxCommandEvent event(XCCALENDARCTRL_HIDECALENDARENTRIES); event.SetInt(calendarID); event.SetId(ID_HIDECALENDARENTRIES); wxPostEvent(this->GetParent()->GetParent()->GetParent(), event); } } void XCCalendarListCalendarCtrl::SetCheckBoxValue(wxCheckBoxState newValue){ if (newValue == wxCHK_CHECKED){ showCalendar = true; } else { showCalendar = false; } chkShowCalendar->SetValue(newValue); } void XCCalendarListCalendarCtrl::PopupMenu( wxMouseEvent &mouseEvent ){ this->GetParent()->GetParent()->GetParent()->GetParent()->PopupMenu(calendarMenu->MenuPointer(), wxDefaultPosition); }