1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-26 00:58:37 +02:00

More uses of safenew

This commit is contained in:
Paul Licameli 2016-08-08 09:54:53 -04:00
parent a52f7f8410
commit 13e056de43
11 changed files with 31 additions and 22 deletions

View File

@ -2740,7 +2740,8 @@ void LabelTrack::CreateCustomGlyphs()
// Create the icon from the tweaked spec. // Create the icon from the tweaked spec.
mBoundaryGlyphs[index] = wxBitmap(XmpBmp); mBoundaryGlyphs[index] = wxBitmap(XmpBmp);
// Create the mask // Create the mask
mBoundaryGlyphs[index].SetMask(new wxMask(mBoundaryGlyphs[index], wxColour(192, 192, 192))); // SetMask takes ownership
mBoundaryGlyphs[index].SetMask(safenew wxMask(mBoundaryGlyphs[index], wxColour(192, 192, 192)));
} }
} }

View File

@ -5370,7 +5370,7 @@ void AudacityProject::OnShowClipping()
void AudacityProject::OnHistory() void AudacityProject::OnHistory()
{ {
if (!mHistoryWindow) if (!mHistoryWindow)
mHistoryWindow = new HistoryWindow(this, GetUndoManager()); mHistoryWindow = safenew HistoryWindow(this, GetUndoManager());
mHistoryWindow->Show(); mHistoryWindow->Show();
mHistoryWindow->Raise(); mHistoryWindow->Raise();
mHistoryWindow->UpdateDisplay(); mHistoryWindow->UpdateDisplay();
@ -5405,7 +5405,7 @@ void AudacityProject::OnPlotSpectrum()
where.x = 150; where.x = 150;
where.y = 150; where.y = 150;
mFreqWindow = new FreqWindow(this, -1, _("Frequency Analysis"), where); mFreqWindow = safenew FreqWindow(this, -1, _("Frequency Analysis"), where);
} }
mFreqWindow->Show(true); mFreqWindow->Show(true);
@ -5422,7 +5422,7 @@ void AudacityProject::OnContrast()
where.x = 150; where.x = 150;
where.y = 150; where.y = 150;
mContrastDialog = new ContrastDialog(this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where); mContrastDialog = safenew ContrastDialog(this, -1, _("Contrast Analysis (WCAG 2 compliance)"), where);
} }
mContrastDialog->CentreOnParent(); mContrastDialog->CentreOnParent();

View File

@ -2033,8 +2033,8 @@ void AudacityProject::OnShow(wxShowEvent & event)
// this is a pure wxWidgets event (no GDK event behind it) and that it // this is a pure wxWidgets event (no GDK event behind it) and that it
// therefore isn't processed within the YieldFor(..) of the clipboard // therefore isn't processed within the YieldFor(..) of the clipboard
// operations (workaround for Debian bug #765341). // operations (workaround for Debian bug #765341).
wxSizeEvent *sizeEvent = new wxSizeEvent(GetSize()); // QueueEvent() will take ownership of the event
GetEventHandler()->QueueEvent(sizeEvent); GetEventHandler()->QueueEvent(safenew wxSizeEvent(GetSize()));
// Further processing by default handlers // Further processing by default handlers
event.Skip(); event.Skip();

View File

@ -2052,7 +2052,7 @@ GuiWaveTrack * ShuttleGui::AddGuiWaveTrack( const wxString & WXUNUSED(Name))
// return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), GuiWaveTrack); // return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), GuiWaveTrack);
GuiWaveTrack * pGuiWaveTrack; GuiWaveTrack * pGuiWaveTrack;
miProp=1; miProp=1;
mpWind = pGuiWaveTrack = new GuiWaveTrack(mpParent, miId, Name); mpWind = pGuiWaveTrack = safenew GuiWaveTrack(mpParent, miId, Name);
mpWind->SetMinSize(wxSize(100,50)); mpWind->SetMinSize(wxSize(100,50));
UpdateSizers(); UpdateSizers();
return pGuiWaveTrack; return pGuiWaveTrack;
@ -2096,7 +2096,7 @@ AttachableScrollBar * ShuttleGui::AddAttachableScrollBar( long style )
// return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), AttachableScrollBar); // return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), AttachableScrollBar);
AttachableScrollBar * pAttachableScrollBar; AttachableScrollBar * pAttachableScrollBar;
miProp=0; miProp=0;
mpWind = pAttachableScrollBar = new AttachableScrollBar( mpWind = pAttachableScrollBar = safenew AttachableScrollBar(
mpParent, mpParent,
miId, miId,
wxDefaultPosition, wxDefaultPosition,

View File

@ -804,7 +804,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.StartStatic(_("Start Date and Time"), true); S.StartStatic(_("Start Date and Time"), true);
{ {
m_pDatePickerCtrl_Start = m_pDatePickerCtrl_Start =
new wxDatePickerCtrl(this, // wxWindow *parent, safenew wxDatePickerCtrl(this, // wxWindow *parent,
ID_DATEPICKER_START, // wxWindowID id, ID_DATEPICKER_START, // wxWindowID id,
m_DateTime_Start); // const wxDateTime& dt = wxDefaultDateTime, m_DateTime_Start); // const wxDateTime& dt = wxDefaultDateTime,
// const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl") // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl")
@ -815,7 +815,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
#endif #endif
S.AddWindow(m_pDatePickerCtrl_Start); S.AddWindow(m_pDatePickerCtrl_Start);
m_pTimeTextCtrl_Start = new NumericTextCtrl( m_pTimeTextCtrl_Start = safenew NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_START); NumericConverter::TIME, this, ID_TIMETEXT_START);
m_pTimeTextCtrl_Start->SetName(_("Start Time")); m_pTimeTextCtrl_Start->SetName(_("Start Time"));
m_pTimeTextCtrl_Start->SetFormatString(strFormat); m_pTimeTextCtrl_Start->SetFormatString(strFormat);
@ -829,7 +829,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.StartStatic(_("End Date and Time"), true); S.StartStatic(_("End Date and Time"), true);
{ {
m_pDatePickerCtrl_End = m_pDatePickerCtrl_End =
new wxDatePickerCtrl(this, // wxWindow *parent, safenew wxDatePickerCtrl(this, // wxWindow *parent,
ID_DATEPICKER_END, // wxWindowID id, ID_DATEPICKER_END, // wxWindowID id,
m_DateTime_End); // const wxDateTime& dt = wxDefaultDateTime, m_DateTime_End); // const wxDateTime& dt = wxDefaultDateTime,
// const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl") // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDP_DEFAULT | wxDP_SHOWCENTURY, const wxValidator& validator = wxDefaultValidator, const wxString& name = "datectrl")
@ -840,7 +840,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
#endif #endif
S.AddWindow(m_pDatePickerCtrl_End); S.AddWindow(m_pDatePickerCtrl_End);
m_pTimeTextCtrl_End = new NumericTextCtrl( m_pTimeTextCtrl_End = safenew NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_END); NumericConverter::TIME, this, ID_TIMETEXT_END);
m_pTimeTextCtrl_End->SetName(_("End Time")); m_pTimeTextCtrl_End->SetName(_("End Time"));
m_pTimeTextCtrl_End->SetFormatString(strFormat); m_pTimeTextCtrl_End->SetFormatString(strFormat);
@ -861,7 +861,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* seconds. * seconds.
*/ */
wxString strFormat1 = _("099 days 024 h 060 m 060 s"); wxString strFormat1 = _("099 days 024 h 060 m 060 s");
m_pTimeTextCtrl_Duration = new NumericTextCtrl(NumericConverter::TIME, this, ID_TIMETEXT_DURATION); m_pTimeTextCtrl_Duration = safenew NumericTextCtrl(NumericConverter::TIME, this, ID_TIMETEXT_DURATION);
m_pTimeTextCtrl_Duration->SetName(_("Duration")); m_pTimeTextCtrl_Duration->SetName(_("Duration"));
m_pTimeTextCtrl_Duration->SetFormatString(strFormat1); m_pTimeTextCtrl_Duration->SetFormatString(strFormat1);
m_pTimeTextCtrl_Duration->SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble()); m_pTimeTextCtrl_Duration->SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble());

View File

@ -556,8 +556,8 @@ protected:
// (no GDK event behind it) and that it therefore isn't processed // (no GDK event behind it) and that it therefore isn't processed
// within the YieldFor(..) of the clipboard operations (workaround // within the YieldFor(..) of the clipboard operations (workaround
// for Debian bug #765341). // for Debian bug #765341).
wxTimerEvent *event = new wxTimerEvent(*this); // QueueEvent() will take ownership of the event
parent->GetEventHandler()->QueueEvent(event); parent->GetEventHandler()->QueueEvent(safenew wxTimerEvent(*this));
} }
TrackPanel *parent; TrackPanel *parent;
} mTimer; } mTimer;

View File

@ -758,7 +758,7 @@ AButton * ToolBar::MakeButton(wxWindow *parent,
wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff)); wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
AButton * button = AButton * button =
new AButton(parent, id, placement, size, *up2, *hilite2, *down2, safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2,
*disable2, processdownevents); *disable2, processdownevents);
return button; return button;

View File

@ -1085,6 +1085,7 @@ void ToolManager::OnMouse( wxMouseEvent & event )
// Done with the floater // Done with the floater
mDragWindow->Destroy(); mDragWindow->Destroy();
mDragWindow = nullptr;
mDragBar->Refresh(false); mDragBar->Refresh(false);
} }
else else
@ -1335,7 +1336,7 @@ void ToolManager::OnGrabber( GrabberEvent & event )
mDragBar->SetPositioned(); mDragBar->SetPositioned();
// Construct a NEW floater // Construct a NEW floater
mDragWindow = new ToolFrame( mParent, this, mDragBar, mp ); mDragWindow = safenew ToolFrame( mParent, this, mDragBar, mp );
// Make sure the ferry is visible // Make sure the ferry is visible
mDragWindow->Show(); mDragWindow->Show();
@ -1377,6 +1378,7 @@ void ToolManager::HandleEscapeKey()
// Done with the floater // Done with the floater
mDragWindow->ClearBar(); mDragWindow->ClearBar();
mDragWindow->Destroy(); mDragWindow->Destroy();
mDragWindow = nullptr;
mDragBar->Refresh(false); mDragBar->Refresh(false);
} }
else { else {

View File

@ -705,7 +705,8 @@ void LWSlider::Draw(wxDC & paintDC)
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
// Now create and set the mask // Now create and set the mask
mThumbBitmap->SetMask(new wxMask(*mThumbBitmap, transparentColour)); // SetMask takes ownership
mThumbBitmap->SetMask(safenew wxMask(*mThumbBitmap, transparentColour));
#endif #endif
// //
@ -884,7 +885,8 @@ void LWSlider::Draw(wxDC & paintDC)
dc.SelectObject(wxNullBitmap); dc.SelectObject(wxNullBitmap);
#if !defined(__WXMAC__) #if !defined(__WXMAC__)
mBitmap->SetMask(new wxMask(*mBitmap, transparentColour)); // SetMask takes ownership
mBitmap->SetMask(safenew wxMask(*mBitmap, transparentColour));
#endif #endif
} }

View File

@ -184,11 +184,13 @@ void ShowModelessErrorDialog(wxWindow *parent,
const wxString &helpURL, const wxString &helpURL,
const bool Close) const bool Close)
{ {
ErrorDialog *dlog = new ErrorDialog(parent, dlogTitle, message, helpURL, Close, false); ErrorDialog *dlog = safenew ErrorDialog(parent, dlogTitle, message, helpURL, Close, false);
dlog->CentreOnParent(); dlog->CentreOnParent();
dlog->Show(); dlog->Show();
// ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak. // ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak.
// ANSWER-ME: This is unused. Delete it or are there plans for it? // ANSWER-ME: This is unused. Delete it or are there plans for it?
// PRL: answer is that the parent window guarantees destruction of the dialog
// but in practice Destroy() in OnOK does that
} }
void ShowAliasMissingDialog(AudacityProject *parent, void ShowAliasMissingDialog(AudacityProject *parent,
@ -197,7 +199,7 @@ void ShowAliasMissingDialog(AudacityProject *parent,
const wxString &helpURL, const wxString &helpURL,
const bool Close) const bool Close)
{ {
ErrorDialog *dlog = new AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false); ErrorDialog *dlog = safenew AliasedFileMissingDialog(parent, dlogTitle, message, helpURL, Close, false);
// Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this. // Don't center because in many cases (effect, export, etc) there will be a progress bar in the center that blocks this.
// instead put it just above or on the top of the project. // instead put it just above or on the top of the project.
wxPoint point; wxPoint point;
@ -214,4 +216,6 @@ void ShowAliasMissingDialog(AudacityProject *parent,
// stop playback AND read dialog's instructions. // stop playback AND read dialog's instructions.
dlog->Show(); dlog->Show();
// ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak. // ANSWER-ME: Vigilant Sentry flags this method as not deleting dlog, so a mem leak.
// PRL: answer is that the parent window guarantees destruction of the dialog
// but in practice Destroy() in OnOK does that
} }

View File

@ -152,7 +152,7 @@ ExpandingToolBar::ExpandingToolBar(wxWindow* parent,
wxColour magicColor = wxColour(0, 255, 255); wxColour magicColor = wxColour(0, 255, 255);
ImageArray fourStates = ImageRoll::SplitV(hbar, magicColor); ImageArray fourStates = ImageRoll::SplitV(hbar, magicColor);
mToggleButton = new AButton(this, kToggleButtonID, mToggleButton = safenew AButton(this, kToggleButtonID,
wxDefaultPosition, wxDefaultSize, wxDefaultPosition, wxDefaultSize,
ImageRoll(ImageRoll::HorizontalRoll, ImageRoll(ImageRoll::HorizontalRoll,
fourStates[0], magicColor), fourStates[0], magicColor),