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

View File

@ -9,6 +9,7 @@
*******************************************************************/
#include "Screenshot.h"
#include "MemoryX.h"
#include "commands/ScreenshotCommand.h"
#include "commands/CommandTargets.h"
#include "commands/CommandDirectory.h"
@ -140,20 +141,20 @@ class ScreenFrameTimer final : public wxTimer
wxEvent & event)
{
screenFrame = frame;
evt = event.Clone();
evt.reset(event.Clone());
}
void Notify() override
{
// Process timer notification just once, then destroy self
evt->SetEventObject(NULL);
screenFrame->ProcessEvent(*evt);
delete evt;
delete this;
}
private:
ScreenFrame *screenFrame;
wxEvent *evt;
std::unique_ptr<wxEvent> evt;
};
////////////////////////////////////////////////////////////////////////////////
@ -463,7 +464,8 @@ bool ScreenFrame::ProcessEvent(wxEvent & e)
e.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED &&
id >= IdAllDelayedEvents && id <= IdLastDelayedEvent &&
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);
return true;
}

View File

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

View File

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

View File

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

View File

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

View File

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