// XCCalendarListAccountCtrl.cpp - XCCalendarListAccountCtrl 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 "XCCalendarListAccountCtrl.h"
BEGIN_EVENT_TABLE(XCCalendarListAccountCtrl, wxPanel)
END_EVENT_TABLE()
using namespace std;
XCCalendarListAccountCtrl::XCCalendarListAccountCtrl(wxWindow* parent, string accountName) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){
// Create the sizer.
szrMain = new wxBoxSizer( wxHORIZONTAL );
this->SetSizer(szrMain);
// Setup the checkbox.
chkShowAll = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, "");
// Setup the label.
lblAccountName = new wxStaticText(this, wxID_ANY, wxString(accountName), wxDefaultPosition, wxDefaultSize, 0, "");
// Setup the font.
wxFont accountFont = lblAccountName->GetFont();
accountFont.MakeBold();
lblAccountName->SetFont(accountFont);
// Connect events to the controls.
chkShowAll->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this);
chkShowAll->SetValue(wxCHK_CHECKED);
// Connect them to the sizer.
szrMain->Add(chkShowAll, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
szrMain->Add(lblAccountName, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
}
XCCalendarListAccountCtrl::~XCCalendarListAccountCtrl(){
// Delete the calendar controls.
for (std::vector::iterator calendarIter = calendarControlList.begin();
calendarIter != calendarControlList.end(); calendarIter++){
delete *calendarIter;
}
// Clear the list of deleted controls.
calendarControlList.clear();
// Clear the widget controls.
}
void XCCalendarListAccountCtrl::AddCalendar(XCCalendarListCalendarCtrl *calendarControl){
// Add the calendar control to the sizer.
//szrMain->Add(calendarControl, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
// Add the calendar control to the list.
calendarControlList.push_back(calendarControl);
}
void XCCalendarListAccountCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
if (chkShowAll->Get3StateValue() == wxCHK_CHECKED){
wxCommandEvent event(XCCALENDARCTRL_SHOWACCOUNTENTRIES);
event.SetInt(accountID);
event.SetId(ID_SHOWENTRIES);
wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
} else {
wxCommandEvent event(XCCALENDARCTRL_HIDEACCOUNTENTRIES);
event.SetInt(accountID);
event.SetId(ID_HIDEENTRIES);
wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
}
}
wxCheckBoxState XCCalendarListAccountCtrl::GetShowCheckboxState(){
return chkShowAll->Get3StateValue();
}
int XCCalendarListAccountCtrl::GetAccountID(){
return accountID;
}
void XCCalendarListAccountCtrl::SetAccountID(int accountID){
this->accountID = accountID;
}
void XCCalendarListAccountCtrl::SetAccountPreferencesID(int accountID){
this->accountPreferencesID = accountPreferencesID;
}
vector XCCalendarListAccountCtrl::GetHiddenCalendarList(){
vector calendarList;
for (vector::iterator calendarControlListIter = calendarControlList.begin();
calendarControlListIter != calendarControlList.end(); calendarControlListIter++){
if ((*calendarControlListIter)->GetShowCheckboxState() == wxCHK_UNCHECKED){
calendarList.push_back((*calendarControlListIter)->GetCalendarID());
}
}
return calendarList;
}
void XCCalendarListAccountCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
if (newValue == wxCHK_CHECKED){
showAccounts = true;
} else {
showAccounts = false;
}
chkShowAll->SetValue(newValue);
}