From f6c21db7e7cac2779ae497511adf99177c492956 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 20 Dec 2018 01:41:04 +0100 Subject: [PATCH] Use of smart pointers --- src/flistbox.cpp | 6 ++---- src/flistview.cpp | 6 ++---- src/fscrollview.cpp | 6 ++---- src/ftextview.cpp | 9 +++------ src/include/final/flistbox.h | 7 +++++-- src/include/final/flistview.h | 5 +++-- src/include/final/fscrollview.h | 7 +++++-- src/include/final/ftextview.h | 7 +++++-- 8 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 21f40eb0..a5283ddd 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -92,8 +92,6 @@ FListBox::FListBox (FWidget* parent) FListBox::~FListBox() // destructor { delOwnTimer(); - delete vbar; - delete hbar; } @@ -817,12 +815,12 @@ void FListBox::init() try { - vbar = new FScrollbar(fc::vertical, this); + vbar = std::make_shared(fc::vertical, this); vbar->setMinimum(0); vbar->setValue(0); vbar->hide(); - hbar = new FScrollbar(fc::horizontal, this); + hbar = std::make_shared(fc::horizontal, this); hbar->setMinimum(0); hbar->setValue(0); hbar->hide(); diff --git a/src/flistview.cpp b/src/flistview.cpp index 1782d932..85a30c6b 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -581,8 +581,6 @@ FListView::FListView (FWidget* parent) FListView::~FListView() // destructor { delOwnTimer(); - delete vbar; - delete hbar; } // public methods of FListView @@ -1390,12 +1388,12 @@ void FListView::init() try { - vbar = new FScrollbar(fc::vertical, this); + vbar = std::make_shared(fc::vertical, this); vbar->setMinimum(0); vbar->setValue(0); vbar->hide(); - hbar = new FScrollbar(fc::horizontal, this); + hbar = std::make_shared(fc::horizontal, this); hbar->setMinimum(0); hbar->setValue(0); hbar->hide(); diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 404a93ec..e03e91d0 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -42,8 +42,6 @@ FScrollView::FScrollView (FWidget* parent) //---------------------------------------------------------------------- FScrollView::~FScrollView() // destructor { - delete vbar; - delete hbar; removeArea (viewport); child_print_area = viewport = nullptr; } @@ -764,12 +762,12 @@ void FScrollView::init_scrollbar() { try { - vbar = new FScrollbar(fc::vertical, this); + vbar = std::make_shared(fc::vertical, this); vbar->setMinimum(0); vbar->setValue(0); vbar->hide(); - hbar = new FScrollbar(fc::horizontal, this); + hbar = std::make_shared(fc::horizontal, this); hbar->setMinimum(0); hbar->setValue(0); hbar->hide(); diff --git a/src/ftextview.cpp b/src/ftextview.cpp index 4c9689ef..05879005 100644 --- a/src/ftextview.cpp +++ b/src/ftextview.cpp @@ -41,10 +41,7 @@ FTextView::FTextView(FWidget* parent) //---------------------------------------------------------------------- FTextView::~FTextView() // destructor -{ - delete vbar; - delete hbar; -} +{ } // public methods of FTextView @@ -624,12 +621,12 @@ void FTextView::init() try { - vbar = new FScrollbar(fc::vertical, this); + vbar = std::make_shared(fc::vertical, this); vbar->setMinimum(0); vbar->setValue(0); vbar->hide(); - hbar = new FScrollbar(fc::horizontal, this); + hbar = std::make_shared(fc::horizontal, this); hbar->setMinimum(0); hbar->setValue(0); hbar->hide(); diff --git a/src/include/final/flistbox.h b/src/include/final/flistbox.h index 5672ee2e..66b44114 100644 --- a/src/include/final/flistbox.h +++ b/src/include/final/flistbox.h @@ -229,6 +229,9 @@ class FListBox : public FWidget virtual void adjustSize(); private: + // Typedef + typedef std::shared_ptr FScrollbarPtr; + // Enumeration enum convert_type { @@ -303,8 +306,8 @@ class FListBox : public FWidget listBoxItems itemlist{}; FWidget::data_ptr source_container{nullptr}; convert_type conv_type{FListBox::no_convert}; - FScrollbar* vbar{nullptr}; - FScrollbar* hbar{nullptr}; + FScrollbarPtr vbar{nullptr}; + FScrollbarPtr hbar{nullptr}; FString text{}; FString inc_search{}; bool multi_select{false}; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index e0509137..f4e409e2 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -356,6 +356,7 @@ class FListView : public FWidget struct Header; // forward declaration typedef std::vector
headerItems; typedef std::vector sortTypes; + typedef std::shared_ptr FScrollbarPtr; // Constants static const int USE_MAX_SIZE = -1; @@ -428,8 +429,8 @@ class FListView : public FWidget FListViewIterator last_visible_line{}; headerItems header{}; FTermBuffer headerline{}; - FScrollbar* vbar{nullptr}; - FScrollbar* hbar{nullptr}; + FScrollbarPtr vbar{nullptr}; + FScrollbarPtr hbar{nullptr}; fc::dragScroll drag_scroll{fc::noScroll}; int scroll_repeat{100}; int scroll_distance{1}; diff --git a/src/include/final/fscrollview.h b/src/include/final/fscrollview.h index ab1bcc37..07977f1a 100644 --- a/src/include/final/fscrollview.h +++ b/src/include/final/fscrollview.h @@ -150,6 +150,9 @@ class FScrollView : public FWidget void copy2area(); private: + // Typedef + typedef std::shared_ptr FScrollbarPtr; + // Constants static const int vertical_border_spacing = 2; static const int horizontal_border_spacing = 2; @@ -177,8 +180,8 @@ class FScrollView : public FWidget FRect scroll_geometry{1, 1, 1, 1}; FRect viewport_geometry{}; term_area* viewport{nullptr}; // virtual scroll content - FScrollbar* vbar{nullptr}; - FScrollbar* hbar{nullptr}; + FScrollbarPtr vbar{nullptr}; + FScrollbarPtr hbar{nullptr}; uInt8 nf_offset{0}; bool border{true}; bool use_own_print_area{false}; diff --git a/src/include/final/ftextview.h b/src/include/final/ftextview.h index 0ad1a87f..535e8058 100644 --- a/src/include/final/ftextview.h +++ b/src/include/final/ftextview.h @@ -127,6 +127,9 @@ class FTextView : public FWidget virtual void adjustSize(); private: + // Typedef + typedef std::shared_ptr FScrollbarPtr; + // Accessors std::size_t getTextHeight(); std::size_t getTextWidth(); @@ -145,8 +148,8 @@ class FTextView : public FWidget // Data Members FStringList data{}; - FScrollbar* vbar{nullptr}; - FScrollbar* hbar{nullptr}; + FScrollbarPtr vbar{nullptr}; + FScrollbarPtr hbar{nullptr}; bool update_scrollbar{true}; int xoffset{0}; int yoffset{0};