Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
widgets: Cleanup objects in destructors and minor code cleanup
[xestiacalendar/.git] / source / widgets / XCCalendarListCalendarCtrl.cpp
1 // XCCalendarListCalendarCtrl.cpp - XCCalendarListCalendarCtrl class
2 //
3 // (c) 2016 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
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.
10 //
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.
15 //
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"
21 using namespace std; 
23 XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string calendarName, Colour calendarColour) : 
24         wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, ""){
26         // Create the sizer.
27         
28         szrMain = new wxBoxSizer( wxHORIZONTAL );
29         this->SetSizer(szrMain);
30         
31         // Setup the checkbox.
32         
33         chkShowCalendar = new wxCheckBox(this, wxID_ANY, "", wxPoint(0,0), wxDefaultSize, wxCHK_3STATE, wxDefaultValidator, "");
34         
35         // Setup the label.
36         
37         lblCalendarName = new wxStaticText(this, wxID_ANY, wxString(calendarName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, "");
38         
39         // Setup the colour.
40                 
41         pnlColour = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(16,16), 0, "");
42         pnlColour->SetBackgroundColour(wxColour(calendarColour.red, calendarColour.green, calendarColour.blue, calendarColour.alpha));
43                 
44         // Setup the popup menu.
45                 
46         calendarMenu = new XCCalendarMenu();
47         calendarMenu->SetWindowPointer(this);
48         calendarMenu->SetPopupPointer((wxPopupTransientWindow*)this->GetParent());
49                 
50         // Connect them to the sizer.
51         
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);
56         
57         // Connect the events to the controls.
58         
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);
65         
66 }
68 XCCalendarListCalendarCtrl::~XCCalendarListCalendarCtrl(){
69         
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);
77         
78         szrMain->Clear();
79         
80         delete chkShowCalendar;
81         chkShowCalendar = nullptr;
82         
83         delete lblCalendarName;
84         lblCalendarName = nullptr;
85         
86         delete imgCalendarIcon;
87         imgCalendarIcon = nullptr;
89         delete calendarMenu;
90         calendarMenu = nullptr;
92         delete pnlColour;
93         pnlColour = nullptr;
95         this->SetSizer(nullptr, true);
96         
97 }
99 wxCheckBoxState XCCalendarListCalendarCtrl::GetShowCheckboxState(){
100         
101         return chkShowCalendar->Get3StateValue();
102         
105 int XCCalendarListCalendarCtrl::GetCalendarID(){
106         
107         return calendarID;
108         
111 void XCCalendarListCalendarCtrl::SetCalendarID(int calendarID){
112         
113         this->calendarID = calendarID;
114         calendarMenu->SetCalendarID(this->calendarID);
115         
118 void XCCalendarListCalendarCtrl::SetAccountPreferencesID(int accountPreferencesID){
119         
120         this->accountPreferencesID = accountPreferencesID;
121         calendarMenu->SetAccountPreferencesID(this->accountPreferencesID);
122         
125 void XCCalendarListCalendarCtrl::ShowAllCheckboxClick( wxMouseEvent &mouseEvent ){
126         
127         if (chkShowCalendar->Get3StateValue() == wxCHK_CHECKED){
128                 
129                 wxCommandEvent event(XCCALENDARCTRL_SHOWCALENDARENTRIES);
130                 event.SetInt(calendarID);
131                 event.SetId(ID_SHOWCALENDARENTRIES);
132                 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
133                 
134         } else {
135                 
136                 wxCommandEvent event(XCCALENDARCTRL_HIDECALENDARENTRIES);
137                 event.SetInt(calendarID);
138                 event.SetId(ID_HIDECALENDARENTRIES);
139                 wxPostEvent(this->GetParent()->GetParent()->GetParent(), event);
140                 
141         }
142         
145 void XCCalendarListCalendarCtrl::SetCheckBoxValue(wxCheckBoxState newValue){
146         
147         if (newValue == wxCHK_CHECKED){
148                 showCalendar = true;
149         } else {
150                 showCalendar = false;           
151         }
152         
153         chkShowCalendar->SetValue(newValue);
154         
157 void XCCalendarListCalendarCtrl::PopupMenu( wxMouseEvent &mouseEvent ){
158         
159         this->GetParent()->GetParent()->GetParent()->GetParent()->PopupMenu(calendarMenu->MenuPointer(), wxDefaultPosition);
160         
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy