From 8943f682f28d38703427a5b8e6edaa79c87327e7 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Mon, 27 Jun 2016 10:58:08 -0400 Subject: [PATCH] some safenew, override, remove an unused function, better comment --- src/widgets/Grid.cpp | 24 +++++++++------------- src/widgets/Grid.h | 38 +++++++++++++++++------------------ src/widgets/NumericTextCtrl.h | 2 +- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/widgets/Grid.cpp b/src/widgets/Grid.cpp index d0584e4a4..9f27a4d30 100644 --- a/src/widgets/Grid.cpp +++ b/src/widgets/Grid.cpp @@ -81,16 +81,6 @@ void TimeEditor::BeginEdit(int row, int col, wxGrid *grid) GetTimeCtrl()->SetFocus(); } -bool TimeEditor::EndEdit(int row, int col, wxGrid *grid) -{ - wxString newvalue; - bool changed = EndEdit(row, col, grid, mOldString, &newvalue); - if (changed) { - ApplyEdit(row, col, grid); - } - return changed; -} - bool TimeEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid *WXUNUSED(grid), const wxString &WXUNUSED(oldval), wxString *newval) { double newtime = GetTimeCtrl()->GetValue(); @@ -156,6 +146,10 @@ void TimeEditor::SetRate(double rate) mRate = rate; } +TimeRenderer::~TimeRenderer() +{ +} + void TimeRenderer::Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, @@ -392,13 +386,15 @@ Grid::Grid(wxWindow *parent, GetGridWindow()->SetAccessible(mAx = safenew GridAx(this)); #endif + // RegisterDataType takes ownership of renderer and editor + RegisterDataType(GRID_VALUE_TIME, - new TimeRenderer, - new TimeEditor); + safenew TimeRenderer, + safenew TimeEditor); RegisterDataType(GRID_VALUE_CHOICE, - new wxGridCellStringRenderer, - new ChoiceEditor); + safenew wxGridCellStringRenderer, + safenew ChoiceEditor); } Grid::~Grid() diff --git a/src/widgets/Grid.h b/src/widgets/Grid.h index 728963d3f..538a336a8 100644 --- a/src/widgets/Grid.h +++ b/src/widgets/Grid.h @@ -46,21 +46,19 @@ class TimeEditor final : public wxGridCellEditor ~TimeEditor(); // Precondition: parent != NULL - void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler); + void Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler) override; - bool IsAcceptedKey(wxKeyEvent &event); + bool IsAcceptedKey(wxKeyEvent &event) override; - void SetSize(const wxRect &rect); + void SetSize(const wxRect &rect) override; - void BeginEdit(int row, int col, wxGrid *grid); + void BeginEdit(int row, int col, wxGrid *grid) override; - bool EndEdit(int row, int col, wxGrid *grid); + bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval) override; - bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval); + void ApplyEdit(int row, int col, wxGrid *grid) override; - void ApplyEdit(int row, int col, wxGrid *grid); - - void Reset(); + void Reset() override; wxString GetFormat(); double GetRate(); @@ -68,7 +66,7 @@ class TimeEditor final : public wxGridCellEditor void SetRate(double rate); wxGridCellEditor *Clone() const override; - wxString GetValue() const; + wxString GetValue() const override; NumericTextCtrl *GetTimeCtrl() const { return (NumericTextCtrl *)m_control; } @@ -89,20 +87,22 @@ class TimeEditor final : public wxGridCellEditor class TimeRenderer final : public wxGridCellRenderer { - public: - void Draw(wxGrid &grid, - wxGridCellAttr &attr, - wxDC &dc, - const wxRect &rect, - int row, - int col, - bool isSelected); +public: + ~TimeRenderer() override; + + void Draw(wxGrid &grid, + wxGridCellAttr &attr, + wxDC &dc, + const wxRect &rect, + int row, + int col, + bool isSelected) override; wxSize GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, - int col); + int col) override; wxGridCellRenderer *Clone() const override; }; diff --git a/src/widgets/NumericTextCtrl.h b/src/widgets/NumericTextCtrl.h index 90baf2f54..cc863af29 100644 --- a/src/widgets/NumericTextCtrl.h +++ b/src/widgets/NumericTextCtrl.h @@ -160,7 +160,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter void SetReadOnly(bool readOnly = true); void EnableMenu(bool enable = true); - // The text control permits typing '-' to make the value invalid only if this + // The text control permits typing DELETE to make the value invalid only if this // function has previously been called. // Maybe you want something other than the default of -1 to indicate the invalid value // this control returns to the program, so you can specify.