1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-24 16:38:07 +02:00

Clone functions required by wxWidgets base classes can use safenew

This commit is contained in:
Paul Licameli 2016-03-31 01:13:29 -04:00
parent 456c8fb01e
commit 83e9e7de97
6 changed files with 22 additions and 14 deletions

@ -9,6 +9,7 @@
*******************************************************************/ *******************************************************************/
#include "Screenshot.h" #include "Screenshot.h"
#include "MemoryX.h"
#include "commands/ScreenshotCommand.h" #include "commands/ScreenshotCommand.h"
#include "commands/CommandTargets.h" #include "commands/CommandTargets.h"
#include "commands/CommandDirectory.h" #include "commands/CommandDirectory.h"
@ -140,20 +141,20 @@ class ScreenFrameTimer final : public wxTimer
wxEvent & event) wxEvent & event)
{ {
screenFrame = frame; screenFrame = frame;
evt = event.Clone(); evt.reset(event.Clone());
} }
void Notify() override void Notify() override
{ {
// Process timer notification just once, then destroy self
evt->SetEventObject(NULL); evt->SetEventObject(NULL);
screenFrame->ProcessEvent(*evt); screenFrame->ProcessEvent(*evt);
delete evt;
delete this; delete this;
} }
private: private:
ScreenFrame *screenFrame; ScreenFrame *screenFrame;
wxEvent *evt; std::unique_ptr<wxEvent> evt;
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -463,7 +464,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
e.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED && e.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED &&
id >= IdAllDelayedEvents && id <= IdLastDelayedEvent && id >= IdAllDelayedEvents && id <= IdLastDelayedEvent &&
e.GetEventObject() != NULL) { e.GetEventObject() != NULL) {
ScreenFrameTimer *timer = new ScreenFrameTimer(this, e); // safenew because it's a one-shot that deletes itself
ScreenFrameTimer *timer = safenew ScreenFrameTimer(this, e);
timer->Start(5000, true); timer->Start(5000, true);
return true; return true;
} }

@ -44,7 +44,7 @@ AppCommandEvent::~AppCommandEvent()
// Clone is required by wxwidgets; implemented via copy constructor // Clone is required by wxwidgets; implemented via copy constructor
wxEvent *AppCommandEvent::Clone() const wxEvent *AppCommandEvent::Clone() const
{ {
return new AppCommandEvent(*this); return safenew AppCommandEvent(*this);
} }
/// Store a pointer to a command object /// Store a pointer to a command object

@ -68,9 +68,10 @@ class GrabberEvent final : public wxCommandEvent
mPos = pos; mPos = pos;
} }
// Clone is required by wxwidgets; implemented via copy constructor
wxEvent *Clone() const override wxEvent *Clone() const override
{ {
return new GrabberEvent(*this); return safenew GrabberEvent(*this);
} }
protected: protected:

@ -125,9 +125,10 @@ bool TimeEditor::IsAcceptedKey(wxKeyEvent &event)
return false; return false;
} }
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellEditor *TimeEditor::Clone() const wxGridCellEditor *TimeEditor::Clone() const
{ {
return new TimeEditor(mFormat, mRate); return safenew TimeEditor(mFormat, mRate);
} }
wxString TimeEditor::GetValue() const wxString TimeEditor::GetValue() const
@ -246,9 +247,10 @@ wxSize TimeRenderer::GetBestSize(wxGrid &grid,
return sz; return sz;
} }
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellRenderer *TimeRenderer::Clone() const wxGridCellRenderer *TimeRenderer::Clone() const
{ {
return new TimeRenderer(); return safenew TimeRenderer();
} }
ChoiceEditor::ChoiceEditor(size_t count, const wxString choices[]) ChoiceEditor::ChoiceEditor(size_t count, const wxString choices[])
@ -272,9 +274,10 @@ ChoiceEditor::~ChoiceEditor()
mHandler.DisconnectEvent(m_control); mHandler.DisconnectEvent(m_control);
} }
// Clone is required by wxwidgets; implemented via copy constructor
wxGridCellEditor *ChoiceEditor::Clone() const wxGridCellEditor *ChoiceEditor::Clone() const
{ {
return new ChoiceEditor(mChoices); return safenew ChoiceEditor(mChoices);
} }
void ChoiceEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) void ChoiceEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler)

@ -67,7 +67,7 @@ class TimeEditor final : public wxGridCellEditor
void SetFormat(const wxString &format); void SetFormat(const wxString &format);
void SetRate(double rate); void SetRate(double rate);
wxGridCellEditor *Clone() const; wxGridCellEditor *Clone() const override;
wxString GetValue() const; wxString GetValue() const;
NumericTextCtrl *GetTimeCtrl() const { return (NumericTextCtrl *)m_control; } NumericTextCtrl *GetTimeCtrl() const { return (NumericTextCtrl *)m_control; }
@ -104,7 +104,7 @@ class TimeRenderer final : public wxGridCellRenderer
int row, int row,
int col); int col);
wxGridCellRenderer *Clone() const; wxGridCellRenderer *Clone() const override;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -141,7 +141,7 @@ public:
void Reset(); void Reset();
wxGridCellEditor *Clone() const; wxGridCellEditor *Clone() const override;
void SetChoices(const wxArrayString &choices); void SetChoices(const wxArrayString &choices);
wxString GetValue() const; wxString GetValue() const;

@ -348,7 +348,8 @@ public:
this->DoSetMax(std::numeric_limits<ValueType>::max()); this->DoSetMax(std::numeric_limits<ValueType>::max());
} }
wxObject *Clone() const override { return new IntegerValidator(*this); } // Clone is required by wxwidgets; implemented via copy constructor
wxObject *Clone() const override { return safenew IntegerValidator(*this); }
private: private:
DECLARE_NO_ASSIGN_CLASS(IntegerValidator); DECLARE_NO_ASSIGN_CLASS(IntegerValidator);
@ -457,9 +458,10 @@ public:
this->SetPrecision(precision); this->SetPrecision(precision);
} }
// Clone is required by wxwidgets; implemented via copy constructor
wxObject *Clone() const override wxObject *Clone() const override
{ {
return new FloatingPointValidator(*this); return safenew FloatingPointValidator(*this);
} }
private: private: