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), 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.
74 wxCheckBoxState XCCalendarListCalendarCtrl::GetShowCheckboxState(){
76 return chkShowCalendar->Get3StateValue();
80 int XCCalendarListCalendarCtrl::GetCalendarID(){
86 void XCCalendarListCalendarCtrl::SetCalendarID(int calendarID){
88 this->calendarID = calendarID;
89 calendarMenu->SetCalendarID(this->calendarID);
93 void XCCalendarListCalendarCtrl::SetAccountPreferencesID(int accountPreferencesID){
95 this->accountPreferencesID = accountPreferencesID;
96 calendarMenu->SetAccountPreferencesID(this->accountPreferencesID);
100 void XCCalendarListCalendarCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
102 if (chkShowCalendar->Get3StateValue() == wxCHK_CHECKED){
104 wxCommandEvent event(XCCALENDARCTRL_SHOWCALENDARENTRIES);
105 event.SetInt(calendarID);
106 event.SetId(ID_SHOWCALENDARENTRIES);
107 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
111 wxCommandEvent event(XCCALENDARCTRL_HIDECALENDARENTRIES);
112 event.SetInt(calendarID);
113 event.SetId(ID_HIDECALENDARENTRIES);
114 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
120 void XCCalendarListCalendarCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
122 if (newValue == wxCHK_CHECKED){
125 showCalendar = false;
128 chkShowCalendar->SetValue(newValue);
132 void XCCalendarListCalendarCtrl::PopupMenu( wxMouseEvent &mouseEvent ){
134 this->GetParent()->GetParent()->GetParent()->GetParent()->PopupMenu(calendarMenu->MenuPointer(), wxDefaultPosition);