1 // XCCalendarListCalendarCtrl.cpp - XCCalendarListCalendarCtrl class
3 // (c) 2016 Xestia Software Development.
5 // This file is part of Xestia Calendar.
7 // Xestia Calendar 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 Calendar 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 "XCCalendarListCalendarCtrl.h"
23 XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string calendarName, Colour calendarColour) :
24 wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){
28 szrMain = new wxBoxSizer( wxHORIZONTAL );
29 this->SetSizer(szrMain);
31 // Setup the checkbox.
33 chkShowCalendar = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, "");
37 lblCalendarName = new wxStaticText(this, wxID_ANY, wxString(calendarName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, "");
41 pnlColour = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(16,16), 0, "");
42 pnlColour->SetBackgroundColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue, calendarColour.alpha));
44 // Setup the popup menu.
46 calendarMenu = new XCCalendarMenu();
47 calendarMenu->SetWindowPointer(this);
48 calendarMenu->SetPopupPointer((wxPopupTransientWindow*)this->GetParent());
50 // Connect them to the sizer.
52 szrMain->Add(15, 0, 0, 0, 5);
53 szrMain->Add(chkShowCalendar, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
54 szrMain->Add(lblCalendarName, 1, wxALL|wxALIGN_CENTER_VERTICAL, 5);
55 szrMain->Add(pnlColour, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
57 // Connect the events to the controls.
59 chkShowCalendar->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this);
60 chkShowCalendar->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
61 lblCalendarName->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
62 pnlColour->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
63 Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
64 chkShowCalendar->SetValue(wxCHK_CHECKED);
68 XCCalendarListCalendarCtrl::~XCCalendarListCalendarCtrl(){
70 // Delete the controls.
72 chkShowCalendar->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this);
73 chkShowCalendar->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
74 lblCalendarName->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
75 pnlColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
76 Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this);
80 delete chkShowCalendar;
81 chkShowCalendar = nullptr;
83 delete lblCalendarName;
84 lblCalendarName = nullptr;
86 delete imgCalendarIcon;
87 imgCalendarIcon = nullptr;
90 calendarMenu = nullptr;
95 this->SetSizer(nullptr, true);
99 wxCheckBoxState XCCalendarListCalendarCtrl::GetShowCheckboxState(){
101 return chkShowCalendar->Get3StateValue();
105 int XCCalendarListCalendarCtrl::GetCalendarID(){
111 void XCCalendarListCalendarCtrl::SetCalendarID(int calendarID){
113 this->calendarID = calendarID;
114 calendarMenu->SetCalendarID(this->calendarID);
118 void XCCalendarListCalendarCtrl::SetAccountPreferencesID(int accountPreferencesID){
120 this->accountPreferencesID = accountPreferencesID;
121 calendarMenu->SetAccountPreferencesID(this->accountPreferencesID);
125 void XCCalendarListCalendarCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
127 if (chkShowCalendar->Get3StateValue() == wxCHK_CHECKED){
129 wxCommandEvent event(XCCALENDARCTRL_SHOWCALENDARENTRIES);
130 event.SetInt(calendarID);
131 event.SetId(ID_SHOWCALENDARENTRIES);
132 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
136 wxCommandEvent event(XCCALENDARCTRL_HIDECALENDARENTRIES);
137 event.SetInt(calendarID);
138 event.SetId(ID_HIDECALENDARENTRIES);
139 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
145 void XCCalendarListCalendarCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
147 if (newValue == wxCHK_CHECKED){
150 showCalendar = false;
153 chkShowCalendar->SetValue(newValue);
157 void XCCalendarListCalendarCtrl::PopupMenu( wxMouseEvent &mouseEvent ){
159 this->GetParent()->GetParent()->GetParent()->GetParent()->PopupMenu(calendarMenu->MenuPointer(), wxDefaultPosition);