1 // XCCalendarListAccountCtrl.cpp - XCCalendarListAccountCtrl 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 "XCCalendarListAccountCtrl.h"
21 BEGIN_EVENT_TABLE(XCCalendarListAccountCtrl, wxPanel)
26 XCCalendarListAccountCtrl::XCCalendarListAccountCtrl(wxWindow* parent, string accountName) :
27 wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){
31 szrMain = new wxBoxSizer( wxHORIZONTAL );
32 this->SetSizer(szrMain);
34 // Setup the checkbox.
36 chkShowAll = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, "");
40 lblAccountName = new wxStaticText(this, wxID_ANY, wxString(accountName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, "");
44 wxFont accountFont = lblAccountName->GetFont();
45 accountFont.MakeBold();
46 lblAccountName->SetFont(accountFont);
48 // Connect events to the controls.
50 chkShowAll->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this);
51 chkShowAll->SetValue(wxCHK_CHECKED);
53 // Connect them to the sizer.
55 szrMain->Add(chkShowAll, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
56 szrMain->Add(lblAccountName, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
60 XCCalendarListAccountCtrl::~XCCalendarListAccountCtrl(){
62 // Delete the calendar controls.
64 // Unbind the controls.
66 chkShowAll->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this);
68 // Delete the calendar list controls.
70 for (std::vector<XCCalendarListCalendarCtrl*>::iterator calendarIter = calendarControlList.begin();
71 calendarIter != calendarControlList.end(); calendarIter++){
77 // Clear the list of deleted controls.
79 calendarControlList.clear();
81 // Clear the widget controls.
86 delete lblAccountName;
87 lblAccountName = nullptr;
89 this->SetSizer(nullptr, true);
93 void XCCalendarListAccountCtrl::AddCalendar(XCCalendarListCalendarCtrl *calendarControl){
95 // Add the calendar control to the sizer.
97 //szrMain->Add(calendarControl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
99 // Add the calendar control to the list.
101 calendarControlList.push_back(calendarControl);
105 void XCCalendarListAccountCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
107 if (chkShowAll->Get3StateValue() == wxCHK_CHECKED){
109 wxCommandEvent event(XCCALENDARCTRL_SHOWACCOUNTENTRIES);
110 event.SetInt(accountID);
111 event.SetId(ID_SHOWENTRIES);
112 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
116 wxCommandEvent event(XCCALENDARCTRL_HIDEACCOUNTENTRIES);
117 event.SetInt(accountID);
118 event.SetId(ID_HIDEENTRIES);
119 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
125 wxCheckBoxState XCCalendarListAccountCtrl::GetShowCheckboxState(){
127 return chkShowAll->Get3StateValue();
131 int XCCalendarListAccountCtrl::GetAccountID(){
137 void XCCalendarListAccountCtrl::SetAccountID(int accountID){
139 this->accountID = accountID;
143 void XCCalendarListAccountCtrl::SetAccountPreferencesID(int accountID){
145 this->accountPreferencesID = accountPreferencesID;
149 vector<int> XCCalendarListAccountCtrl::GetHiddenCalendarList(){
151 vector<int> calendarList;
153 for (vector<XCCalendarListCalendarCtrl*>::iterator calendarControlListIter = calendarControlList.begin();
154 calendarControlListIter != calendarControlList.end(); calendarControlListIter++){
156 if ((*calendarControlListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
158 calendarList.push_back((*calendarControlListIter)->GetCalendarID());
168 void XCCalendarListAccountCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
170 if (newValue == wxCHK_CHECKED){
173 showAccounts = false;
176 chkShowAll->SetValue(newValue);