From 902d948e5e45ad483c8e235690dda8f2bf596ad5 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Fri, 2 Feb 2018 00:05:18 +0000 Subject: [PATCH] widgets: Cleanup objects in destructors and minor code cleanup --- source/widgets/XCCalendarCtrl.cpp | 24 ++++++++ source/widgets/XCCalendarDay.cpp | 38 ++++++++++++- source/widgets/XCCalendarDayEntry.cpp | 41 +++++++++++++- source/widgets/XCCalendarDayEntry.h | 1 - source/widgets/XCCalendarList.cpp | 13 +++++ source/widgets/XCCalendarListAccountCtrl.cpp | 16 +++++- source/widgets/XCCalendarListCalendarCtrl.cpp | 27 ++++++++- source/widgets/XCCalendarManipulator.cpp | 56 +++++++++++++++++++ source/widgets/XCCalendarMenu.cpp | 16 +----- source/widgets/XCCalendarMenu.h | 1 - source/widgets/XCCalendarMonthSelect.cpp | 12 ++++ source/widgets/XCCalendarMonthView.cpp | 22 ++++++++ source/widgets/XCCalendarMonthView.h | 1 - .../widgets/XCCalendarMonthViewDayTitle.cpp | 12 ++++ source/widgets/XCEventMenu.cpp | 16 +----- source/widgets/XCEventMenu.h | 3 - 16 files changed, 262 insertions(+), 37 deletions(-) diff --git a/source/widgets/XCCalendarCtrl.cpp b/source/widgets/XCCalendarCtrl.cpp index 5a9e598..8bd5696 100644 --- a/source/widgets/XCCalendarCtrl.cpp +++ b/source/widgets/XCCalendarCtrl.cpp @@ -85,6 +85,30 @@ XCCalendarCtrl::XCCalendarCtrl(wxWindow *parent, CalendarDataStorage *dataStorag XCCalendarCtrl::~XCCalendarCtrl(){ // Destory the controls in the XCCalendarCtrl class. + + Unbind(XCCALENDARCTRL_CHANGEGRID, &XCCalendarCtrl::UpdateGrid, this, ID_CHANGEGRID); + Unbind(XCCALENDARCTRL_HIDEACCOUNTENTRIES, &XCCalendarCtrl::HideAccountEntries, this, ID_HIDEENTRIES); + Unbind(XCCALENDARCTRL_SHOWACCOUNTENTRIES, &XCCalendarCtrl::ShowAccountEntries, this, ID_SHOWENTRIES); + Unbind(XCCALENDARCTRL_HIDECALENDARENTRIES, &XCCalendarCtrl::HideCalendarEntries, this, ID_HIDECALENDARENTRIES); + Unbind(XCCALENDARCTRL_SHOWCALENDARENTRIES, &XCCalendarCtrl::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES); + Unbind(XCCALENDARCTRL_DELETECALENDARENTRIES, &XCCalendarCtrl::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES); + Unbind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY); + Unbind(XCCALENDARCTRL_ADDENTRY, &XCCalendarCtrl::AddCalendarEntry, this, ID_ADDENTRY); + Unbind(XCCALENDARCTRL_UPDATEENTRY, &XCCalendarCtrl::UpdateCalendarEntry, this, ID_UPDATEENTRY); + Unbind(XCCALENDARCTRL_DELETEENTRY, &XCCalendarCtrl::DeleteCalendarEntry, this, ID_DELETEENTRY); + Unbind(XCCALENDARCTRL_UPDATECALENDARCOLOUR, &XCCalendarCtrl::UpdateCalendarColour, this, ID_UPDATECOLOUR); + + szrMain->Clear(); + + delete monthViewCtrl; + monthViewCtrl = nullptr; + + delete manipulatorCtrl; + manipulatorCtrl = nullptr; + + calendarStorage = nullptr; + + this->SetSizer(nullptr, true); } diff --git a/source/widgets/XCCalendarDay.cpp b/source/widgets/XCCalendarDay.cpp index 78c1687..656ad75 100644 --- a/source/widgets/XCCalendarDay.cpp +++ b/source/widgets/XCCalendarDay.cpp @@ -118,6 +118,18 @@ XCCalendarDay::~XCCalendarDay(){ // Destory the controls from the widget. + Unbind(XCCALENDARDAY_DESELECTOTHERENTRIES, &XCCalendarDay::DeselectOthersEvent, this, ID_DESELECTOTHERENTRIES); + Unbind(XCCALENDARDAY_DESELECTALLENTRIES, &XCCalendarDay::DeselectAllEvent, this, ID_DESELECTALLITEMS); + Unbind(XCCALENDARDAY_HIDEACCOUNTENTRIES, &XCCalendarDay::HideAccountEntries, this, ID_HIDEENTRIES); + Unbind(XCCALENDARDAY_SHOWACCOUNTENTRIES, &XCCalendarDay::ShowAccountEntries, this, ID_SHOWENTRIES); + Unbind(XCCALENDARDAY_HIDECALENDARENTRIES, &XCCalendarDay::HideCalendarEntries, this, ID_HIDECALENDARENTRIES); + Unbind(XCCALENDARDAY_SHOWCALENDARENTRIES, &XCCalendarDay::ShowCalendarEntries, this, ID_SHOWCALENDARENTRIES); + Unbind(XCCALENDARDAY_DELETECALENDARENTRIES, &XCCalendarDay::DeleteCalendarEntries, this, ID_DELETECALENDARENTRIES); + Unbind(XCCALENDARDAY_DELETEENTRY, &XCCalendarDay::DeleteCalendarEntry, this, ID_DELETEENTRY); + Unbind(XCCALENDARDAY_ADDENTRY, &XCCalendarDay::AddCalendarEntry, this, ID_ADDENTRY); + Unbind(XCCALENDARDAY_UPDATEENTRY, &XCCalendarDay::UpdateCalendarEntry, this, ID_UPDATEENTRY); + Unbind(XCCALENDARDAY_UPDATECALENDARCOLOUR, &XCCalendarDay::UpdateCalendarColour, this, ID_UPDATECOLOUR); + for (vector::iterator calendarEntryIter = calendarEntryList.begin(); calendarEntryIter != calendarEntryList.end(); calendarEntryIter++){ @@ -125,6 +137,14 @@ XCCalendarDay::~XCCalendarDay(){ } + eventListFrameSizer->Clear(); + + eventListFrame->SetSizer(nullptr, true); + + mainSectionSizer->Clear(); + topSectionSizer->Clear(); + windowSizer->Clear(); + delete alertIcon; alertIcon = nullptr; @@ -134,8 +154,22 @@ XCCalendarDay::~XCCalendarDay(){ delete eventListFrame; eventListFrame = nullptr; + delete numberText; + numberText = nullptr; + + delete topPanel; + topPanel = nullptr; + + delete mainPanel; + mainPanel = nullptr; + calendarEntryList.clear(); + this->SetSizer(nullptr, true); + + monthViewPointer = nullptr; + dataStorage = nullptr; + } void XCCalendarDay::UpdateTopIcons(){ @@ -538,7 +572,8 @@ void XCCalendarDay::AddCalendarEntry(wxCommandEvent &eventData){ EventProperties *eventInfo = (EventProperties*)eventData.GetClientData(); - XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, eventInfo->eventName, wxDefaultPosition, wxDefaultSize, eventInfo->eventID); + // TODO: Fix conversion from string to wxString + XCCalendarDayEntry *newEntry = new XCCalendarDayEntry(eventListFrame, wxString(eventInfo->eventName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, eventInfo->eventID); CDSGetCalendarInfo calendarInfo = dataStorage->GetCalendar(eventInfo->calendarID); @@ -599,7 +634,6 @@ void XCCalendarDay::UpdateCalendarEntry(wxCommandEvent &eventData){ (*calendarEntryIter)->SetEventName(eventInfo->eventName); (*calendarEntryIter)->SetTime(eventInfo->eventHour, eventInfo->eventMinute, eventInfo->eventSecond); - } } diff --git a/source/widgets/XCCalendarDayEntry.cpp b/source/widgets/XCCalendarDayEntry.cpp index 82b8b9c..034e5e7 100644 --- a/source/widgets/XCCalendarDayEntry.cpp +++ b/source/widgets/XCCalendarDayEntry.cpp @@ -101,6 +101,45 @@ XCCalendarDayEntry::~XCCalendarDayEntry(){ // Destory the controls from the widget. + // Disconnect and unbind. + + calendarColour->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + alarmIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + highPriorityIcon->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventText->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + eventTime->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + dayPanel->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(XCCalendarDayEntry::LeftClick), NULL, this); + + calendarColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + alarmIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + highPriorityIcon->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventText->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + eventTime->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + dayPanel->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarDayEntry::RightClick), NULL, this); + + Unbind(XCCALENDARDAYENTRY_DESELECT, &XCCalendarDayEntry::Deselect, this, ID_ENTRYDESELECT); + + // Delete the controls. + + mainSizer->Clear(); + + delete eventText; + eventText = nullptr; + + delete eventTime; + eventTime = nullptr; + + delete calendarColour; + calendarColour = nullptr; + + delete mainPanel; + mainPanel = nullptr; + + delete highPriorityIcon; + delete alarmIcon; + + this->SetSizer(nullptr, true); + } void XCCalendarDayEntry::UpdateInformation(){ @@ -350,7 +389,7 @@ void XCCalendarDayEntry::SetAfterSpacer(wxSizerItem *afterSpacer){ void XCCalendarDayEntry::SetEventName(string eventName){ - eventText->SetLabel((wxString)eventName); + eventText->SetLabel(wxString(eventName)); } diff --git a/source/widgets/XCCalendarDayEntry.h b/source/widgets/XCCalendarDayEntry.h index c82faf2..823a44c 100644 --- a/source/widgets/XCCalendarDayEntry.h +++ b/source/widgets/XCCalendarDayEntry.h @@ -48,7 +48,6 @@ class XCCalendarDayEntry: public wxPanel wxStaticBitmap *highPriorityIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxPoint(14,7), wxDefaultSize, 0 ); wxStaticBitmap *alarmIcon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxPoint(30,7), wxDefaultSize, 0 ); wxBoxSizer *mainSizer = nullptr; - wxBoxSizer *borderSizer = nullptr; wxSizerItem *afterSpacer = nullptr; wxBitmap alarmIconBitmap; wxBitmap priorityIconBitmap; diff --git a/source/widgets/XCCalendarList.cpp b/source/widgets/XCCalendarList.cpp index 9dae3fc..92e7c50 100644 --- a/source/widgets/XCCalendarList.cpp +++ b/source/widgets/XCCalendarList.cpp @@ -31,6 +31,19 @@ XCCalendarList::XCCalendarList(wxWindow *parent) XCCalendarList::~XCCalendarList(){ + // Delete the calendar lists. + + for (vector::iterator accountCtrlIter = accountControlList.begin(); + accountCtrlIter != accountControlList.end(); accountCtrlIter++){ + + delete *accountCtrlIter; + + } + + accountControlList.clear(); + + this->SetSizer(nullptr, true); + } void XCCalendarList::UpdateCalendarList(CalendarDataStorage *dataStorage){ diff --git a/source/widgets/XCCalendarListAccountCtrl.cpp b/source/widgets/XCCalendarListAccountCtrl.cpp index 46d0e36..dbd105e 100644 --- a/source/widgets/XCCalendarListAccountCtrl.cpp +++ b/source/widgets/XCCalendarListAccountCtrl.cpp @@ -37,7 +37,7 @@ XCCalendarListAccountCtrl::XCCalendarListAccountCtrl(wxWindow* parent, string ac // Setup the label. - lblAccountName = new wxStaticText(this, wxID_ANY, wxString(accountName), wxDefaultPosition, wxDefaultSize, 0, ""); + lblAccountName = new wxStaticText(this, wxID_ANY, wxString(accountName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, ""); // Setup the font. @@ -61,6 +61,12 @@ XCCalendarListAccountCtrl::~XCCalendarListAccountCtrl(){ // Delete the calendar controls. + // Unbind the controls. + + chkShowAll->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListAccountCtrl::ShowAllCheckboxClick), NULL, this); + + // Delete the calendar list controls. + for (std::vector::iterator calendarIter = calendarControlList.begin(); calendarIter != calendarControlList.end(); calendarIter++){ @@ -73,6 +79,14 @@ XCCalendarListAccountCtrl::~XCCalendarListAccountCtrl(){ calendarControlList.clear(); // Clear the widget controls. + + delete chkShowAll; + chkShowAll = nullptr; + + delete lblAccountName; + lblAccountName = nullptr; + + this->SetSizer(nullptr, true); } diff --git a/source/widgets/XCCalendarListCalendarCtrl.cpp b/source/widgets/XCCalendarListCalendarCtrl.cpp index 3729231..371b123 100644 --- a/source/widgets/XCCalendarListCalendarCtrl.cpp +++ b/source/widgets/XCCalendarListCalendarCtrl.cpp @@ -34,7 +34,7 @@ XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string // Setup the label. - lblCalendarName = new wxStaticText(this, wxID_ANY, wxString(calendarName), wxDefaultPosition, wxDefaultSize, 0, ""); + lblCalendarName = new wxStaticText(this, wxID_ANY, wxString(calendarName.c_str(), wxConvUTF8), wxDefaultPosition, wxDefaultSize, 0, ""); // Setup the colour. @@ -68,6 +68,31 @@ XCCalendarListCalendarCtrl::XCCalendarListCalendarCtrl(wxWindow* parent, string XCCalendarListCalendarCtrl::~XCCalendarListCalendarCtrl(){ // Delete the controls. + + chkShowCalendar->Disconnect(wxEVT_COMMAND_CHECKBOX_CLICKED, wxMouseEventHandler(XCCalendarListCalendarCtrl::ShowAllCheckboxClick), NULL, this); + chkShowCalendar->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + lblCalendarName->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + pnlColour->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(XCCalendarListCalendarCtrl::PopupMenu), NULL, this); + + szrMain->Clear(); + + delete chkShowCalendar; + chkShowCalendar = nullptr; + + delete lblCalendarName; + lblCalendarName = nullptr; + + delete imgCalendarIcon; + imgCalendarIcon = nullptr; + + delete calendarMenu; + calendarMenu = nullptr; + + delete pnlColour; + pnlColour = nullptr; + + this->SetSizer(nullptr, true); } diff --git a/source/widgets/XCCalendarManipulator.cpp b/source/widgets/XCCalendarManipulator.cpp index 79ed65e..81843b5 100644 --- a/source/widgets/XCCalendarManipulator.cpp +++ b/source/widgets/XCCalendarManipulator.cpp @@ -137,6 +137,62 @@ XCCalendarManipulator::XCCalendarManipulator(wxWindow* parent, const wxString& t XCCalendarManipulator::~XCCalendarManipulator(){ // Destory the controls from the widget. + + dateButton->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::DateTextClick), NULL, this); + nextButton->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::NextMonth), NULL, this); + calendarsButton->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::ShowCalendarsList), NULL, this); + previousButton->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarManipulator::PreviousMonth), NULL, this); + +#if defined(WIN32) + dateButton->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this); + dateButton->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this); + nextButton->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this); + nextButton->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this); + calendarsButton->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this); + calendarsButton->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this); + previousButton->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseover), NULL, this); + previousButton->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(XCCalendarManipulator::ButtonMouseout), NULL, this); +#endif + + Unbind(XCCALENDARMANIPULATOR_CHANGEGRID, &XCCalendarManipulator::ChangeGrid, this, ID_CHANGEGRID); + + // Delete the buttons in pnlMain. + + szrNavigation->Clear(); + + delete previousButton; + previousButton = nullptr; + + delete nextButton; + nextButton = nullptr; + + delete calendarsButton; + calendarsButton = nullptr; + + delete dateButton; + dateButton = nullptr; + + // Delete szrNavigation. + + szrMain->Clear(); + pnlMain->SetSizer(nullptr, true); + + // Delete pnlMain itself; + + delete pnlMain; + pnlMain = nullptr; + + delete moo; + moo = nullptr; + + delete calendarList; + calendarList = nullptr; + + // Delete szrMain itself; + + this->SetSizer(nullptr, true); + + dataStorage = nullptr; } diff --git a/source/widgets/XCCalendarMenu.cpp b/source/widgets/XCCalendarMenu.cpp index 1ca0550..2cb9a7c 100644 --- a/source/widgets/XCCalendarMenu.cpp +++ b/source/widgets/XCCalendarMenu.cpp @@ -31,22 +31,12 @@ XCCalendarMenu::~XCCalendarMenu(){ // Destory the XCCalendarMenu object. - // Delete the menu items. - - for (std::map::iterator menuItemIter = menuItems.begin(); - menuItemIter != menuItems.end(); ++menuItemIter){ - - // Delete the wxMenuItem object. - - this->Disconnect(menuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(XCCalendarMenu::ProcessMenuItemClick) ); - delete(menuItemIter->second); - menuItemIter->second = NULL; - - } + // Delete the list of items in menuItems (not the menu items themselves). menuItems.clear(); + // Menu items are deleted through ~wxMenuBase() + } void XCCalendarMenu::AppendMenuItem(wxString objectName, diff --git a/source/widgets/XCCalendarMenu.h b/source/widgets/XCCalendarMenu.h index 7d440ac..403735f 100644 --- a/source/widgets/XCCalendarMenu.h +++ b/source/widgets/XCCalendarMenu.h @@ -46,7 +46,6 @@ class XCCalendarMenu : public XCCalendarMenuADT { private: std::map menuItems = {}; - wxListCtrl *contactListCtrl = NULL; wxWindow *windowPtr = NULL; wxPopupTransientWindow *popupPtr = NULL; bool enableAccountSettings = FALSE; diff --git a/source/widgets/XCCalendarMonthSelect.cpp b/source/widgets/XCCalendarMonthSelect.cpp index 6c46280..cb45c1b 100644 --- a/source/widgets/XCCalendarMonthSelect.cpp +++ b/source/widgets/XCCalendarMonthSelect.cpp @@ -65,7 +65,19 @@ XCCalendarMonthSelect::XCCalendarMonthSelect(wxWindow *parent) XCCalendarMonthSelect::~XCCalendarMonthSelect(){ + szrMain->Clear(); + delete cmbMonth; + cmbMonth = nullptr; + + delete spcYear; + spcYear = nullptr; + + btnChange->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(XCCalendarMonthSelect::UpdateMonthView), NULL, this); + delete btnChange; + btnChange = nullptr; + + this->SetSizer(nullptr, true); } diff --git a/source/widgets/XCCalendarMonthView.cpp b/source/widgets/XCCalendarMonthView.cpp index 6f801e5..941a484 100644 --- a/source/widgets/XCCalendarMonthView.cpp +++ b/source/widgets/XCCalendarMonthView.cpp @@ -91,6 +91,7 @@ XCCalendarMonthView::XCCalendarMonthView(wxWindow *parent, const wxString& title Bind(XCCALENDARMONTH_ADDENTRY, &XCCalendarMonthView::AddCalendarEntry, this, ID_ADDENTRY); Bind(XCCALENDARMONTH_UPDATEENTRY, &XCCalendarMonthView::UpdateCalendarEntry, this, ID_UPDATEENTRY); Bind(XCCALENDARMONTH_UPDATECALENDARCOLOUR, &XCCalendarMonthView::UpdateCalendarColour, this, ID_UPDATECOLOUR); + } XCCalendarMonthView::~XCCalendarMonthView(){ @@ -110,6 +111,27 @@ XCCalendarMonthView::~XCCalendarMonthView(){ } + delete eventMenu; + this->SetSizer(nullptr, true); + + // Unbind events from control + + Unbind(XCCALENDARMONTH_DESELECTOTHERENTRIES, &XCCalendarMonthView::DeselectOthersEvent, this); + Unbind(XCCALENDARMONTH_HIDEACCOUNTENTRIES, &XCCalendarMonthView::HideAccountEntries, this); + Unbind(XCCALENDARMONTH_SHOWACCOUNTENTRIES, &XCCalendarMonthView::ShowAccountEntries, this); + Unbind(XCCALENDARMONTH_HIDECALENDARENTRIES, &XCCalendarMonthView::HideCalendarEntries, this); + Unbind(XCCALENDARMONTH_SHOWCALENDARENTRIES, &XCCalendarMonthView::ShowCalendarEntries, this); + Unbind(XCCALENDARMONTH_DELETECALENDARENTRIES, &XCCalendarMonthView::DeleteCalendarEntries, this); + Unbind(XCCALENDARMONTH_DISPLAYEVENTMENU, &XCCalendarMonthView::ShowEventMenu, this); + Unbind(XCCALENDARMONTH_DELETEENTRY, &XCCalendarMonthView::DeleteCalendarEntry, this); + Unbind(XCCALENDARMONTH_ADDENTRY, &XCCalendarMonthView::AddCalendarEntry, this); + Unbind(XCCALENDARMONTH_UPDATEENTRY, &XCCalendarMonthView::UpdateCalendarEntry, this); + Unbind(XCCALENDARMONTH_UPDATECALENDARCOLOUR, &XCCalendarMonthView::UpdateCalendarColour, this); + + // Don't delete CalendarDataStorage object (used elsewhere). + + calendarStorage = nullptr; + } void XCCalendarMonthView::ProcessGrid(XCCalendarMonthViewGrid *grid, std::vector *hideAccounts, std::vector *hideCalendars){ diff --git a/source/widgets/XCCalendarMonthView.h b/source/widgets/XCCalendarMonthView.h index 5eb3253..35e2054 100644 --- a/source/widgets/XCCalendarMonthView.h +++ b/source/widgets/XCCalendarMonthView.h @@ -43,7 +43,6 @@ class XCCalendarMonthView: public wxPanel private: wxFlexGridSizer *windowSizer = new wxFlexGridSizer(0, 7, 1, 1); vector calendarDayList; - wxStaticText *numberText = nullptr; XCCalendarMonthViewDayTitle *mondayText = nullptr; XCCalendarMonthViewDayTitle *tuesdayText = nullptr; XCCalendarMonthViewDayTitle *wednesdayText = nullptr; diff --git a/source/widgets/XCCalendarMonthViewDayTitle.cpp b/source/widgets/XCCalendarMonthViewDayTitle.cpp index c2fb6d5..0b638f9 100644 --- a/source/widgets/XCCalendarMonthViewDayTitle.cpp +++ b/source/widgets/XCCalendarMonthViewDayTitle.cpp @@ -39,4 +39,16 @@ XCCalendarMonthViewDayTitle::~XCCalendarMonthViewDayTitle() // Delete the objects. + daySizer->Remove(0); + delete dayText; + dayText = nullptr; + + dayPanel->SetSizer(nullptr, true); + + windowSizer->Remove(windowSizer); + delete dayPanel; + dayPanel = nullptr; + + this->SetSizer(nullptr, true); + } \ No newline at end of file diff --git a/source/widgets/XCEventMenu.cpp b/source/widgets/XCEventMenu.cpp index 6c02caa..ac3b5ec 100644 --- a/source/widgets/XCEventMenu.cpp +++ b/source/widgets/XCEventMenu.cpp @@ -31,22 +31,12 @@ XCEventMenu::~XCEventMenu(){ // Destory the XCEventMenu object. - // Delete the menu items. - - for (std::map::iterator menuItemIter = menuItems.begin(); - menuItemIter != menuItems.end(); ++menuItemIter){ - - // Delete the wxMenuItem object. - - this->Disconnect(menuItemIter->second->GetId(), wxEVT_COMMAND_MENU_SELECTED, - wxCommandEventHandler(XCEventMenu::ProcessMenuItemClick) ); - delete(menuItemIter->second); - menuItemIter->second = NULL; - - } + // Remove items from list (but don't delete). menuItems.clear(); + // Menu items are deleted through ~wxMenuBase() + } void XCEventMenu::AppendMenuItem(wxString objectName, diff --git a/source/widgets/XCEventMenu.h b/source/widgets/XCEventMenu.h index 02662f2..dab6023 100644 --- a/source/widgets/XCEventMenu.h +++ b/source/widgets/XCEventMenu.h @@ -36,9 +36,6 @@ class XCEventMenuADT : public wxMenu protected: virtual void ProcessMenuItemClick(wxCommandEvent& event) {event.Skip();}; - public: - XCEventMenuADT(){}; - ~XCEventMenuADT(){}; }; -- 2.39.5