Use of smart pointers

This commit is contained in:
Markus Gans 2018-12-20 01:41:04 +01:00
parent f3bdc3b410
commit f6c21db7e7
8 changed files with 27 additions and 26 deletions

View File

@ -92,8 +92,6 @@ FListBox::FListBox (FWidget* parent)
FListBox::~FListBox() // destructor FListBox::~FListBox() // destructor
{ {
delOwnTimer(); delOwnTimer();
delete vbar;
delete hbar;
} }
@ -817,12 +815,12 @@ void FListBox::init()
try try
{ {
vbar = new FScrollbar(fc::vertical, this); vbar = std::make_shared<FScrollbar>(fc::vertical, this);
vbar->setMinimum(0); vbar->setMinimum(0);
vbar->setValue(0); vbar->setValue(0);
vbar->hide(); vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();

View File

@ -581,8 +581,6 @@ FListView::FListView (FWidget* parent)
FListView::~FListView() // destructor FListView::~FListView() // destructor
{ {
delOwnTimer(); delOwnTimer();
delete vbar;
delete hbar;
} }
// public methods of FListView // public methods of FListView
@ -1390,12 +1388,12 @@ void FListView::init()
try try
{ {
vbar = new FScrollbar(fc::vertical, this); vbar = std::make_shared<FScrollbar>(fc::vertical, this);
vbar->setMinimum(0); vbar->setMinimum(0);
vbar->setValue(0); vbar->setValue(0);
vbar->hide(); vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();

View File

@ -42,8 +42,6 @@ FScrollView::FScrollView (FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FScrollView::~FScrollView() // destructor FScrollView::~FScrollView() // destructor
{ {
delete vbar;
delete hbar;
removeArea (viewport); removeArea (viewport);
child_print_area = viewport = nullptr; child_print_area = viewport = nullptr;
} }
@ -764,12 +762,12 @@ void FScrollView::init_scrollbar()
{ {
try try
{ {
vbar = new FScrollbar(fc::vertical, this); vbar = std::make_shared<FScrollbar>(fc::vertical, this);
vbar->setMinimum(0); vbar->setMinimum(0);
vbar->setValue(0); vbar->setValue(0);
vbar->hide(); vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();

View File

@ -41,10 +41,7 @@ FTextView::FTextView(FWidget* parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FTextView::~FTextView() // destructor FTextView::~FTextView() // destructor
{ { }
delete vbar;
delete hbar;
}
// public methods of FTextView // public methods of FTextView
@ -624,12 +621,12 @@ void FTextView::init()
try try
{ {
vbar = new FScrollbar(fc::vertical, this); vbar = std::make_shared<FScrollbar>(fc::vertical, this);
vbar->setMinimum(0); vbar->setMinimum(0);
vbar->setValue(0); vbar->setValue(0);
vbar->hide(); vbar->hide();
hbar = new FScrollbar(fc::horizontal, this); hbar = std::make_shared<FScrollbar>(fc::horizontal, this);
hbar->setMinimum(0); hbar->setMinimum(0);
hbar->setValue(0); hbar->setValue(0);
hbar->hide(); hbar->hide();

View File

@ -229,6 +229,9 @@ class FListBox : public FWidget
virtual void adjustSize(); virtual void adjustSize();
private: private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
// Enumeration // Enumeration
enum convert_type enum convert_type
{ {
@ -303,8 +306,8 @@ class FListBox : public FWidget
listBoxItems itemlist{}; listBoxItems itemlist{};
FWidget::data_ptr source_container{nullptr}; FWidget::data_ptr source_container{nullptr};
convert_type conv_type{FListBox::no_convert}; convert_type conv_type{FListBox::no_convert};
FScrollbar* vbar{nullptr}; FScrollbarPtr vbar{nullptr};
FScrollbar* hbar{nullptr}; FScrollbarPtr hbar{nullptr};
FString text{}; FString text{};
FString inc_search{}; FString inc_search{};
bool multi_select{false}; bool multi_select{false};

View File

@ -356,6 +356,7 @@ class FListView : public FWidget
struct Header; // forward declaration struct Header; // forward declaration
typedef std::vector<Header> headerItems; typedef std::vector<Header> headerItems;
typedef std::vector<fc::sorting_type> sortTypes; typedef std::vector<fc::sorting_type> sortTypes;
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
// Constants // Constants
static const int USE_MAX_SIZE = -1; static const int USE_MAX_SIZE = -1;
@ -428,8 +429,8 @@ class FListView : public FWidget
FListViewIterator last_visible_line{}; FListViewIterator last_visible_line{};
headerItems header{}; headerItems header{};
FTermBuffer headerline{}; FTermBuffer headerline{};
FScrollbar* vbar{nullptr}; FScrollbarPtr vbar{nullptr};
FScrollbar* hbar{nullptr}; FScrollbarPtr hbar{nullptr};
fc::dragScroll drag_scroll{fc::noScroll}; fc::dragScroll drag_scroll{fc::noScroll};
int scroll_repeat{100}; int scroll_repeat{100};
int scroll_distance{1}; int scroll_distance{1};

View File

@ -150,6 +150,9 @@ class FScrollView : public FWidget
void copy2area(); void copy2area();
private: private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
// Constants // Constants
static const int vertical_border_spacing = 2; static const int vertical_border_spacing = 2;
static const int horizontal_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 scroll_geometry{1, 1, 1, 1};
FRect viewport_geometry{}; FRect viewport_geometry{};
term_area* viewport{nullptr}; // virtual scroll content term_area* viewport{nullptr}; // virtual scroll content
FScrollbar* vbar{nullptr}; FScrollbarPtr vbar{nullptr};
FScrollbar* hbar{nullptr}; FScrollbarPtr hbar{nullptr};
uInt8 nf_offset{0}; uInt8 nf_offset{0};
bool border{true}; bool border{true};
bool use_own_print_area{false}; bool use_own_print_area{false};

View File

@ -127,6 +127,9 @@ class FTextView : public FWidget
virtual void adjustSize(); virtual void adjustSize();
private: private:
// Typedef
typedef std::shared_ptr<FScrollbar> FScrollbarPtr;
// Accessors // Accessors
std::size_t getTextHeight(); std::size_t getTextHeight();
std::size_t getTextWidth(); std::size_t getTextWidth();
@ -145,8 +148,8 @@ class FTextView : public FWidget
// Data Members // Data Members
FStringList data{}; FStringList data{};
FScrollbar* vbar{nullptr}; FScrollbarPtr vbar{nullptr};
FScrollbar* hbar{nullptr}; FScrollbarPtr hbar{nullptr};
bool update_scrollbar{true}; bool update_scrollbar{true};
int xoffset{0}; int xoffset{0};
int yoffset{0}; int yoffset{0};