1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 17:09:26 +02:00

Remove some naked new amd delete in: widgets

This commit is contained in:
Paul Licameli 2016-04-06 18:32:14 -04:00 committed by Paul Licameli
parent 0bb17c174e
commit 71efb13161
15 changed files with 111 additions and 204 deletions

View File

@ -8,6 +8,7 @@
**********************************************************************/ **********************************************************************/
#include "Audacity.h"
#include "Snap.h" #include "Snap.h"
#include <algorithm> #include <algorithm>

View File

@ -520,23 +520,6 @@ void LWSlider::Init(wxWindow * parent,
LWSlider::~LWSlider() LWSlider::~LWSlider()
{ {
if (mBitmap)
{
delete mBitmap;
mBitmap = NULL;
}
if (mThumbBitmap)
{
delete mThumbBitmap;
mThumbBitmap = NULL;
}
delete mpRuler;
if (mTipPanel)
{
delete mTipPanel;
}
} }
wxWindowID LWSlider::GetId() wxWindowID LWSlider::GetId()
@ -658,18 +641,6 @@ void LWSlider::OnSize( wxSizeEvent & event )
void LWSlider::Draw(wxDC & paintDC) void LWSlider::Draw(wxDC & paintDC)
{ {
if (mBitmap)
{
delete mBitmap;
mBitmap = NULL;
}
if (mThumbBitmap)
{
delete mThumbBitmap;
mThumbBitmap = NULL;
}
// The color we'll use to create the mask // The color we'll use to create the mask
wxColour transparentColour(255, 254, 255); wxColour transparentColour(255, 254, 255);
@ -677,7 +648,7 @@ void LWSlider::Draw(wxDC & paintDC)
wxMemoryDC dc; wxMemoryDC dc;
// Create the bitmap // Create the bitmap
mThumbBitmap = new wxBitmap(); mThumbBitmap = std::make_unique<wxBitmap>();
mThumbBitmap->Create(mThumbWidth, mThumbHeight, paintDC); mThumbBitmap->Create(mThumbWidth, mThumbHeight, paintDC);
dc.SelectObject(*mThumbBitmap); dc.SelectObject(*mThumbBitmap);
@ -687,50 +658,49 @@ void LWSlider::Draw(wxDC & paintDC)
dc.Clear(); dc.Clear();
#endif #endif
// Create the graphics contexxt
wxGraphicsContext *gc = wxGraphicsContext::Create(dc);
// For vertical, we use the same downward pointing thumb, but rotate and flip it
if (mOrientation == wxVERTICAL)
{ {
gc->Translate(0, 3); // Create the graphics contexxt
gc->Scale(1, -1); std::unique_ptr<wxGraphicsContext> gc{ wxGraphicsContext::Create(dc) };
gc->Rotate((-90 * M_PI) / 180);
// For vertical, we use the same downward pointing thumb, but rotate and flip it
if (mOrientation == wxVERTICAL)
{
gc->Translate(0, 3);
gc->Scale(1, -1);
gc->Rotate((-90 * M_PI) / 180);
}
else
{
gc->Translate(1.5, 0);
}
// Draw the thumb outline
gc->SetBrush(wxBrush(mEnabled ? wxColour(192, 192, 216) : wxColour(238, 238, 238)));
gc->SetPen(wxPen(mEnabled ? wxColour(0, 0, 0) : wxColour(119, 119, 119)));
gc->DrawLines(WXSIZEOF(outer), outer);
// The interior is based on whether the slider is enabled or not
if (mEnabled)
{
// Draw the left and top interior components
gc->SetPen(wxPen(wxColour(255, 255, 255)));
gc->StrokeLines(WXSIZEOF(enabledLeftBegin), enabledLeftBegin, enabledLeftEnd);
// Draw the right and bottom interior components
gc->SetPen(wxPen(wxColour(141, 141, 178)));
gc->StrokeLines(WXSIZEOF(enabledRightBegin), enabledRightBegin, enabledRightEnd);
}
else
{
// Draw the interior stripes
gc->SetPen(wxPen(wxColour(200, 200, 200)));
gc->StrokeLines(WXSIZEOF(disabledStripesBegin), disabledStripesBegin, disabledStripesEnd);
// Draw the right and bottom interior components
gc->SetPen(wxPen(wxColour(153, 153, 153)));
gc->StrokeLines(WXSIZEOF(disabledRightBegin), disabledRightBegin, disabledRightEnd);
}
} }
else
{
gc->Translate(1.5, 0);
}
// Draw the thumb outline
gc->SetBrush(wxBrush(mEnabled ? wxColour(192, 192, 216) : wxColour(238, 238, 238)));
gc->SetPen(wxPen(mEnabled ? wxColour(0, 0, 0) : wxColour(119, 119, 119)));
gc->DrawLines(WXSIZEOF(outer), outer);
// The interior is based on whether the slider is enabled or not
if (mEnabled)
{
// Draw the left and top interior components
gc->SetPen(wxPen(wxColour(255, 255, 255)));
gc->StrokeLines(WXSIZEOF(enabledLeftBegin), enabledLeftBegin, enabledLeftEnd);
// Draw the right and bottom interior components
gc->SetPen(wxPen(wxColour(141, 141, 178)));
gc->StrokeLines(WXSIZEOF(enabledRightBegin), enabledRightBegin, enabledRightEnd);
}
else
{
// Draw the interior stripes
gc->SetPen(wxPen(wxColour(200, 200, 200)));
gc->StrokeLines(WXSIZEOF(disabledStripesBegin), disabledStripesBegin, disabledStripesEnd);
// Draw the right and bottom interior components
gc->SetPen(wxPen(wxColour(153, 153, 153)));
gc->StrokeLines(WXSIZEOF(disabledRightBegin), disabledRightBegin, disabledRightEnd);
}
// Done with the graphics context and memory DC
delete gc;
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
@ -742,7 +712,7 @@ void LWSlider::Draw(wxDC & paintDC)
// Now the background bitmap // Now the background bitmap
// //
mBitmap = new wxBitmap(); mBitmap = std::make_unique<wxBitmap>();
mBitmap->Create(mWidth, mHeight, paintDC); mBitmap->Create(mWidth, mHeight, paintDC);
dc.SelectObject(*mBitmap); dc.SelectObject(*mBitmap);
@ -934,8 +904,7 @@ void LWSlider::ShowTip(bool show)
return; return;
} }
delete mTipPanel; mTipPanel.reset();
mTipPanel = NULL;
} }
CreatePopWin(); CreatePopWin();
@ -948,21 +917,14 @@ void LWSlider::ShowTip(bool show)
if (mTipPanel) if (mTipPanel)
{ {
mTipPanel->Hide(); mTipPanel->Hide();
delete mTipPanel; mTipPanel.reset();
mTipPanel = NULL;
} }
} }
} }
void LWSlider::CreatePopWin() void LWSlider::CreatePopWin()
{ {
if (mTipPanel) mTipPanel = std::make_unique<TipPanel>(mParent, GetMaxTip());
{
delete mTipPanel;
mTipPanel = NULL;
}
mTipPanel = new TipPanel(mParent, GetMaxTip());
} }
void LWSlider::SetPopWinPosition() void LWSlider::SetPopWinPosition()
@ -1555,11 +1517,7 @@ void LWSlider::SetEnabled(bool enabled)
{ {
mEnabled = enabled; mEnabled = enabled;
if (mThumbBitmap) mThumbBitmap.reset();
{
delete mThumbBitmap;
mThumbBitmap = NULL;
}
Refresh(); Refresh();
} }
@ -1593,7 +1551,7 @@ ASlider::ASlider( wxWindow * parent,
int orientation /*= wxHORIZONTAL*/) int orientation /*= wxHORIZONTAL*/)
: wxPanel( parent, id, pos, size, wxWANTS_CHARS ) : wxPanel( parent, id, pos, size, wxWANTS_CHARS )
{ {
mLWSlider = new LWSlider( this, mLWSlider = std::make_unique<LWSlider>( this,
name, name,
wxPoint(0,0), wxPoint(0,0),
size, size,
@ -1621,7 +1579,6 @@ ASlider::~ASlider()
{ {
if(HasCapture()) if(HasCapture())
ReleaseMouse(); ReleaseMouse();
delete mLWSlider;
} }
void ASlider::OnSlider(wxCommandEvent &event) void ASlider::OnSlider(wxCommandEvent &event)

View File

@ -228,15 +228,14 @@ class LWSlider
wxWindowID mID; wxWindowID mID;
TipPanel *mTipPanel; std::unique_ptr<TipPanel> mTipPanel;
wxString mTipTemplate; wxString mTipTemplate;
Ruler* mpRuler; std::unique_ptr<Ruler> mpRuler;
bool mIsDragging; bool mIsDragging;
wxBitmap *mBitmap; std::unique_ptr<wxBitmap> mBitmap, mThumbBitmap;
wxBitmap *mThumbBitmap;
// AD: True if this object owns *mThumbBitmap (sometimes mThumbBitmap points // AD: True if this object owns *mThumbBitmap (sometimes mThumbBitmap points
// to an object we shouldn't DELETE) -- once we get theming totally right // to an object we shouldn't DELETE) -- once we get theming totally right
@ -311,7 +310,7 @@ public:
static TempAllowFocus TemporarilyAllowFocus(); static TempAllowFocus TemporarilyAllowFocus();
private: private:
LWSlider *mLWSlider; std::unique_ptr<LWSlider> mLWSlider;
bool mSliderIsFocused; bool mSliderIsFocused;
wxTimer mTimer; wxTimer mTimer;

View File

@ -131,7 +131,7 @@ ExpandingToolBar::ExpandingToolBar(wxWindow* parent,
mFrameParent(NULL), mFrameParent(NULL),
mDialogParent(NULL), mDialogParent(NULL),
mAreaParent(NULL), mAreaParent(NULL),
mSavedArrangement(NULL), mSavedArrangement{},
mDragImage(NULL), mDragImage(NULL),
mTopLevelParent(NULL) mTopLevelParent(NULL)
{ {
@ -632,13 +632,10 @@ void ExpandingToolBar::FinishMoving()
msNoAutoExpandStack--; msNoAutoExpandStack--;
if (mDropTarget == kDummyRect) { if (mDropTarget == kDummyRect) {
mAreaParent->RestoreArrangement(mSavedArrangement); mAreaParent->RestoreArrangement(std::move(mSavedArrangement));
mSavedArrangement = NULL;
} }
else { else {
delete mSavedArrangement; mSavedArrangement.reset();
mSavedArrangement = NULL;
mAreaParent->MoveChild(this, mDropTarget); mAreaParent->MoveChild(this, mDropTarget);
} }
@ -1182,9 +1179,9 @@ void ToolBarArea::RemoveChild(ExpandingToolBar *child)
} }
} }
ToolBarArrangement *ToolBarArea::SaveArrangement() std::unique_ptr<ToolBarArrangement> ToolBarArea::SaveArrangement()
{ {
ToolBarArrangement *arrangement = new ToolBarArrangement(); auto arrangement = std::make_unique<ToolBarArrangement>();
int i; int i;
arrangement->childArray = mChildArray; arrangement->childArray = mChildArray;
@ -1196,7 +1193,7 @@ ToolBarArrangement *ToolBarArea::SaveArrangement()
return arrangement; return arrangement;
} }
void ToolBarArea::RestoreArrangement(ToolBarArrangement *arrangement) void ToolBarArea::RestoreArrangement(std::unique_ptr<ToolBarArrangement>&& arrangement)
{ {
int i; int i;
@ -1210,7 +1207,7 @@ void ToolBarArea::RestoreArrangement(ToolBarArrangement *arrangement)
Fit(false, true); Fit(false, true);
delete arrangement; arrangement.reset();
} }
wxArrayRect ToolBarArea::GetDropTargets() wxArrayRect ToolBarArea::GetDropTargets()

View File

@ -11,6 +11,7 @@
#ifndef __AUDACITY_EXPANDING_TOOL_BAR__ #ifndef __AUDACITY_EXPANDING_TOOL_BAR__
#define __AUDACITY_EXPANDING_TOOL_BAR__ #define __AUDACITY_EXPANDING_TOOL_BAR__
#include "../MemoryX.h"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/dialog.h> #include <wx/dialog.h>
#include <wx/dynarray.h> #include <wx/dynarray.h>
@ -108,7 +109,7 @@ class ExpandingToolBar final : public wxPanelWrapper
ToolBarFrame *mFrameParent; ToolBarFrame *mFrameParent;
ToolBarDialog *mDialogParent; ToolBarDialog *mDialogParent;
ToolBarArea *mAreaParent; ToolBarArea *mAreaParent;
ToolBarArrangement *mSavedArrangement; std::unique_ptr<ToolBarArrangement> mSavedArrangement;
ImageRollPanel *mTargetPanel; ImageRollPanel *mTargetPanel;
wxDragImage *mDragImage; wxDragImage *mDragImage;
wxWindow *mTopLevelParent; wxWindow *mTopLevelParent;
@ -217,8 +218,8 @@ class ToolBarArea final : public wxPanelWrapper
void AddChild(ExpandingToolBar *child); void AddChild(ExpandingToolBar *child);
void RemoveChild(ExpandingToolBar *child); void RemoveChild(ExpandingToolBar *child);
ToolBarArrangement *SaveArrangement(); std::unique_ptr<ToolBarArrangement> SaveArrangement();
void RestoreArrangement(ToolBarArrangement *arrangement); void RestoreArrangement(std::unique_ptr<ToolBarArrangement>&& arrangement);
wxArrayRect GetDropTargets(); wxArrayRect GetDropTargets();
void MoveChild(ExpandingToolBar *child, wxRect dropTarget); void MoveChild(ExpandingToolBar *child, wxRect dropTarget);

View File

@ -411,11 +411,11 @@ Grid::Grid(wxWindow *parent,
Grid::~Grid() Grid::~Grid()
{ {
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
int cnt = mChildren.GetCount(); int cnt = mChildren.size();
while (cnt--) {
while (cnt) { // PRL: I found this loop destroying right-to-left.
GridAx *ax = (GridAx *) mChildren[--cnt]; // Is the sequence of destruction important?
delete ax; mChildren.pop_back();
} }
#endif #endif
} }

View File

@ -11,6 +11,8 @@
#ifndef __AUDACITY_WIDGETS_GRID__ #ifndef __AUDACITY_WIDGETS_GRID__
#define __AUDACITY_WIDGETS_GRID__ #define __AUDACITY_WIDGETS_GRID__
#include "../MemoryX.h"
#include <vector>
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/choice.h> #include <wx/choice.h>
#include <wx/dynarray.h> #include <wx/dynarray.h>
@ -224,7 +226,7 @@ class Grid final : public wxGrid
#if wxUSE_ACCESSIBILITY #if wxUSE_ACCESSIBILITY
GridAx *mAx; GridAx *mAx;
wxArrayPtrVoid mChildren; std::vector<movable_ptr<GridAx>> mChildren;
int mObjNdx; int mObjNdx;
#endif #endif

View File

@ -237,8 +237,8 @@ Meter::Meter(AudacityProject *project,
mActive(false), mActive(false),
mNumBars(0), mNumBars(0),
mLayoutValid(false), mLayoutValid(false),
mBitmap(NULL), mBitmap{},
mIcon(NULL), mIcon{},
mAccSilent(false) mAccSilent(false)
{ {
// Suppress warnings about the header file // Suppress warnings about the header file
@ -316,11 +316,11 @@ Meter::Meter(AudacityProject *project,
{ {
if(mIsInput) if(mIsInput)
{ {
mIcon = new wxBitmap(MicMenuNarrow_xpm); mIcon = std::make_unique<wxBitmap>(MicMenuNarrow_xpm);
} }
else else
{ {
mIcon = new wxBitmap(SpeakerMenuNarrow_xpm); mIcon = std::make_unique<wxBitmap>(SpeakerMenuNarrow_xpm);
} }
} }
@ -369,10 +369,6 @@ Meter::~Meter()
// is active. // is active.
if (gAudioIO->IsMonitoring()) if (gAudioIO->IsMonitoring())
gAudioIO->StopStream(); gAudioIO->StopStream();
if (mIcon)
delete mIcon;
if (mBitmap)
delete mBitmap;
} }
void Meter::UpdatePrefs() void Meter::UpdatePrefs()
@ -427,21 +423,16 @@ void Meter::OnErase(wxEraseEvent & WXUNUSED(event))
void Meter::OnPaint(wxPaintEvent & WXUNUSED(event)) void Meter::OnPaint(wxPaintEvent & WXUNUSED(event))
{ {
#if defined(__WXMAC__) #if defined(__WXMAC__)
wxPaintDC *paintDC = new wxPaintDC(this); auto paintDC = std::make_unique<wxPaintDC>(this);
#else #else
wxDC *paintDC = wxAutoBufferedPaintDCFactory(this); std::unique_ptr<wxDC> paintDC{ wxAutoBufferedPaintDCFactory(this) };
#endif #endif
wxDC & destDC = *paintDC; wxDC & destDC = *paintDC;
if (mLayoutValid == false) if (mLayoutValid == false)
{ {
if (mBitmap)
{
delete mBitmap;
}
// Create a NEW one using current size and select into the DC // Create a NEW one using current size and select into the DC
mBitmap = new wxBitmap(); mBitmap = std::make_unique<wxBitmap>();
mBitmap->Create(mWidth, mHeight, destDC); mBitmap->Create(mWidth, mHeight, destDC);
wxMemoryDC dc; wxMemoryDC dc;
dc.SelectObject(*mBitmap); dc.SelectObject(*mBitmap);
@ -664,8 +655,6 @@ void Meter::OnPaint(wxPaintEvent & WXUNUSED(event))
wxRect r = mIconRect; wxRect r = mIconRect;
AColor::DrawFocus(destDC, r.Inflate(1, 1)); AColor::DrawFocus(destDC, r.Inflate(1, 1));
} }
delete paintDC;
} }
void Meter::OnSize(wxSizeEvent & WXUNUSED(event)) void Meter::OnSize(wxSizeEvent & WXUNUSED(event))

View File

@ -261,13 +261,13 @@ class Meter final : public wxPanelWrapper
bool mLayoutValid; bool mLayoutValid;
wxBitmap *mBitmap; std::unique_ptr<wxBitmap> mBitmap;
wxRect mIconRect; wxRect mIconRect;
wxPoint mLeftTextPos; wxPoint mLeftTextPos;
wxPoint mRightTextPos; wxPoint mRightTextPos;
wxSize mLeftSize; wxSize mLeftSize;
wxSize mRightSize; wxSize mRightSize;
wxBitmap *mIcon; std::unique_ptr<wxBitmap> mIcon;
wxPen mPen; wxPen mPen;
wxPen mDisabledPen; wxPen mDisabledPen;
wxPen mPeakPeakPen; wxPen mPeakPeakPen;

View File

@ -1175,9 +1175,9 @@ NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
bool autoPos): bool autoPos):
wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS), wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
NumericConverter(type, formatName, timeValue, sampleRate), NumericConverter(type, formatName, timeValue, sampleRate),
mBackgroundBitmap(NULL), mBackgroundBitmap{},
mDigitFont(NULL), mDigitFont{},
mLabelFont(NULL), mLabelFont{},
mLastField(1), mLastField(1),
mAutoPos(autoPos) mAutoPos(autoPos)
, mType(type) , mType(type)
@ -1211,12 +1211,6 @@ NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
NumericTextCtrl::~NumericTextCtrl() NumericTextCtrl::~NumericTextCtrl()
{ {
if (mBackgroundBitmap)
delete mBackgroundBitmap;
if (mDigitFont)
delete mDigitFont;
if (mLabelFont)
delete mLabelFont;
} }
// Set the focus to the first (left-most) non-zero digit // Set the focus to the first (left-most) non-zero digit
@ -1306,12 +1300,9 @@ bool NumericTextCtrl::Layout()
int x, pos; int x, pos;
wxMemoryDC memDC; wxMemoryDC memDC;
if (mBackgroundBitmap) {
delete mBackgroundBitmap;
mBackgroundBitmap = NULL;
}
// Placeholder bitmap so the memDC has something to reference // Placeholder bitmap so the memDC has something to reference
mBackgroundBitmap = new wxBitmap(1, 1); mBackgroundBitmap = std::make_unique<wxBitmap>(1, 1);
memDC.SelectObject(*mBackgroundBitmap); memDC.SelectObject(*mBackgroundBitmap);
mDigits.Clear(); mDigits.Clear();
@ -1335,9 +1326,7 @@ bool NumericTextCtrl::Layout()
} }
fontSize--; fontSize--;
if (mDigitFont) mDigitFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
delete mDigitFont;
mDigitFont = new wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
memDC.SetFont(*mDigitFont); memDC.SetFont(*mDigitFont);
memDC.GetTextExtent(exampleText, &strW, &strH); memDC.GetTextExtent(exampleText, &strW, &strH);
mDigitW = strW; mDigitW = strW;
@ -1345,9 +1334,7 @@ bool NumericTextCtrl::Layout()
// The label font should be a little smaller // The label font should be a little smaller
fontSize--; fontSize--;
if (mLabelFont) mLabelFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
delete mLabelFont;
mLabelFont = new wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
// Figure out the x-position of each field and label in the box // Figure out the x-position of each field and label in the box
x = mBorderLeft; x = mBorderLeft;
@ -1382,8 +1369,7 @@ bool NumericTextCtrl::Layout()
wxBrush Brush; wxBrush Brush;
delete mBackgroundBitmap; // Delete placeholder mBackgroundBitmap = std::make_unique<wxBitmap>(mWidth + mButtonWidth, mHeight);
mBackgroundBitmap = new wxBitmap(mWidth + mButtonWidth, mHeight);
memDC.SelectObject(*mBackgroundBitmap); memDC.SelectObject(*mBackgroundBitmap);
memDC.SetBrush(*wxLIGHT_GREY_BRUSH); memDC.SetBrush(*wxLIGHT_GREY_BRUSH);

View File

@ -15,6 +15,7 @@
#ifndef __AUDACITY_TIME_TEXT_CTRL__ #ifndef __AUDACITY_TIME_TEXT_CTRL__
#define __AUDACITY_TIME_TEXT_CTRL__ #define __AUDACITY_TIME_TEXT_CTRL__
#include "../MemoryX.h"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/dynarray.h> #include <wx/dynarray.h>
#include <wx/event.h> #include <wx/event.h>
@ -193,10 +194,9 @@ private:
bool mMenuEnabled; bool mMenuEnabled;
bool mReadOnly; bool mReadOnly;
wxBitmap *mBackgroundBitmap; std::unique_ptr<wxBitmap> mBackgroundBitmap;
wxFont *mDigitFont; std::unique_ptr<wxFont> mDigitFont, mLabelFont;
wxFont *mLabelFont;
int mDigitBoxW; int mDigitBoxW;
int mDigitBoxH; int mDigitBoxH;
int mDigitW; int mDigitW;

View File

@ -1013,11 +1013,7 @@ ProgressDialog::~ProgressDialog()
{ {
// Delete the window disabler before hiding the dialog to allow // Delete the window disabler before hiding the dialog to allow
// focus to return to the original window. // focus to return to the original window.
if (mDisable) mDisable.reset();
{
delete mDisable;
mDisable = NULL;
}
if (IsShown()) if (IsShown())
{ {
@ -1261,7 +1257,7 @@ bool ProgressDialog::Create(const wxString & title,
// while waiting for Timer Record to start -- and then also // while waiting for Timer Record to start -- and then also
// while it's recording, it has a ProgressDialog, so really, // while it's recording, it has a ProgressDialog, so really,
// no editing in any project until Timer Record finishes. // no editing in any project until Timer Record finishes.
mDisable = new wxWindowDisabler(this); mDisable = std::make_unique<wxWindowDisabler>(this);
return true; return true;
} }

View File

@ -20,6 +20,7 @@
#include "../Audacity.h" #include "../Audacity.h"
#include "../MemoryX.h"
#include <wx/defs.h> #include <wx/defs.h>
#include <wx/evtloop.h> #include <wx/evtloop.h>
#include <wx/gauge.h> #include <wx/gauge.h>
@ -113,7 +114,7 @@ private:
// This guarantees we have an active event loop...possible during OnInit() // This guarantees we have an active event loop...possible during OnInit()
wxEventLoopGuarantor mLoop; wxEventLoopGuarantor mLoop;
wxWindowDisabler *mDisable; std::unique_ptr<wxWindowDisabler> mDisable;
wxStaticText *mMessage; wxStaticText *mMessage;
int mLastW; int mLastW;

View File

@ -105,7 +105,7 @@ wxColour Ruler::mTickColour{ 153, 153, 153 };
// //
Ruler::Ruler() Ruler::Ruler()
: mpNumberScale(0) : mpNumberScale{}
{ {
mMin = mHiddenMin = 0.0; mMin = mHiddenMin = 0.0;
mMax = mHiddenMax = 100.0; mMax = mHiddenMax = 100.0;
@ -136,9 +136,9 @@ Ruler::Ruler()
fontSize = 8; fontSize = 8;
#endif #endif
mMinorMinorFont = new wxFont(fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); mMinorMinorFont = std::make_unique<wxFont>(fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
mMinorFont = new wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); mMinorFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
mMajorFont = new wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); mMajorFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
mUserFonts = false; mUserFonts = false;
@ -170,9 +170,6 @@ Ruler::~Ruler()
Invalidate(); // frees up our arrays Invalidate(); // frees up our arrays
if( mUserBits ) if( mUserBits )
delete [] mUserBits;//JKC delete [] mUserBits;//JKC
delete mMinorFont;
delete mMajorFont;
delete mMinorMinorFont;
if (mMajorLabels) if (mMajorLabels)
delete[] mMajorLabels; delete[] mMajorLabels;
@ -180,8 +177,6 @@ Ruler::~Ruler()
delete[] mMinorLabels; delete[] mMinorLabels;
if (mMinorMinorLabels) if (mMinorMinorLabels)
delete[] mMinorMinorLabels; delete[] mMinorMinorLabels;
delete mpNumberScale;
} }
void Ruler::SetTwoTone(bool twoTone) void Ruler::SetTwoTone(bool twoTone)
@ -322,14 +317,13 @@ void Ruler::SetNumberScale(const NumberScale *pScale)
{ {
if (!pScale) { if (!pScale) {
if (mpNumberScale) { if (mpNumberScale) {
delete mpNumberScale; mpNumberScale.reset();
Invalidate(); Invalidate();
} }
} }
else { else {
if (!mpNumberScale || *mpNumberScale != *pScale) { if (!mpNumberScale || *mpNumberScale != *pScale) {
delete mpNumberScale; mpNumberScale = std::make_unique<NumberScale>(*pScale);
mpNumberScale = new NumberScale(*pScale);
Invalidate(); Invalidate();
} }
} }
@ -1028,17 +1022,11 @@ void Ruler::Update(const TimeTrack* timetrack)// Envelope *speedEnv, long minSpe
mDC->GetTextExtent(exampleText, &strW, &strH, &strD, &strL); mDC->GetTextExtent(exampleText, &strW, &strH, &strD, &strL);
mLead = strL; mLead = strL;
if (mMajorFont) mMajorFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
delete mMajorFont;
mMajorFont = new wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
if (mMinorFont) mMinorFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
delete mMinorFont;
mMinorFont = new wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
if (mMinorMinorFont) mMinorMinorFont = std::make_unique<wxFont>(fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
delete mMinorMinorFont;
mMinorMinorFont = new wxFont(fontSize - 1, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
} }
// If ruler is being resized, we could end up with it being too small. // If ruler is being resized, we could end up with it being too small.
@ -2013,11 +2001,6 @@ AdornedRulerPanel::~AdornedRulerPanel()
if(HasCapture()) if(HasCapture())
ReleaseMouse(); ReleaseMouse();
// Done with the snap manager
if (mSnapManager) {
delete mSnapManager;
}
wxTheApp->Disconnect(EVT_AUDIOIO_CAPTURE, wxTheApp->Disconnect(EVT_AUDIOIO_CAPTURE,
wxCommandEventHandler(AdornedRulerPanel::OnCapture), wxCommandEventHandler(AdornedRulerPanel::OnCapture),
NULL, NULL,
@ -2424,10 +2407,7 @@ void AdornedRulerPanel::OnMouseEvents(wxMouseEvent &evt)
SetCursor(mCursorDefault); SetCursor(mCursorDefault);
mIsWE = false; mIsWE = false;
if (mSnapManager) { mSnapManager.reset();
delete mSnapManager;
mSnapManager = NULL;
}
if(evt.Leaving()) if(evt.Leaving())
return; return;
@ -2929,7 +2909,7 @@ void AdornedRulerPanel::DragSelection()
void AdornedRulerPanel::HandleSnapping() void AdornedRulerPanel::HandleSnapping()
{ {
if (!mSnapManager) { if (!mSnapManager) {
mSnapManager = new SnapManager(mTracks, mViewInfo); mSnapManager = std::make_unique<SnapManager>(mTracks, mViewInfo);
} }
bool snappedPoint, snappedTime; bool snappedPoint, snappedTime;

View File

@ -12,7 +12,6 @@
#define __AUDACITY_RULER__ #define __AUDACITY_RULER__
#include "OverlayPanel.h" #include "OverlayPanel.h"
#include "../MemoryX.h" #include "../MemoryX.h"
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/dc.h> #include <wx/dc.h>
@ -105,7 +104,7 @@ class AUDACITY_DLL_API Ruler {
void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont); void SetFonts(const wxFont &minorFont, const wxFont &majorFont, const wxFont &minorMinorFont);
struct Fonts { wxFont *major, *minor, *minorMinor; }; struct Fonts { wxFont *major, *minor, *minorMinor; };
Fonts GetFonts() const Fonts GetFonts() const
{ return { mMajorFont, mMinorFont, mMinorMinorFont }; } { return { mMajorFont.get(), mMinorFont.get(), mMinorMinorFont.get() }; }
// Copies *pScale if it is not NULL // Copies *pScale if it is not NULL
void SetNumberScale(const NumberScale *pScale); void SetNumberScale(const NumberScale *pScale);
@ -181,8 +180,7 @@ private:
int mLengthOld; int mLengthOld;
wxDC *mDC; wxDC *mDC;
wxFont *mMinorFont, *mMajorFont; std::unique_ptr<wxFont> mMinorFont, mMajorFont, mMinorMinorFont;
wxFont *mMinorMinorFont;
bool mUserFonts; bool mUserFonts;
double mMin, mMax; double mMin, mMax;
@ -240,7 +238,7 @@ private:
const ZoomInfo *mUseZoomInfo; const ZoomInfo *mUseZoomInfo;
int mLeftOffset; int mLeftOffset;
NumberScale *mpNumberScale; std::unique_ptr<NumberScale> mpNumberScale;
}; };
class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper { class AUDACITY_DLL_API RulerPanel final : public wxPanelWrapper {
@ -401,7 +399,7 @@ private:
double mIndTime; double mIndTime;
double mQuickPlayPos; double mQuickPlayPos;
SnapManager *mSnapManager; std::unique_ptr<SnapManager> mSnapManager;
bool mIsSnapped; bool mIsSnapped;
bool mPlayRegionLock; bool mPlayRegionLock;