1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-14 08:36:27 +01:00

Use macro safenew for many allocations of wxWindow subclasses

This commit is contained in:
Paul Licameli
2016-02-13 18:06:49 -05:00
parent 6052b5f9be
commit 3f237daddc
42 changed files with 238 additions and 214 deletions

View File

@@ -95,6 +95,7 @@ for registering for changes.
#include "Audacity.h"
#include <memory>
#include <wx/wx.h>
#include <wx/wxprec.h>
#include <wx/listctrl.h>
@@ -216,7 +217,7 @@ void ShuttleGuiBase::AddPrompt(const wxString &Prompt)
if( mShuttleMode != eIsCreating )
return;
miProp=1;
mpWind = new wxStaticText(mpParent, -1, Prompt, wxDefaultPosition, wxDefaultSize,
mpWind = safenew wxStaticText(GetParent(), -1, Prompt, wxDefaultPosition, wxDefaultSize,
Style( wxALIGN_RIGHT ));
mpWind->SetName(wxStripMenuCodes(Prompt)); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
UpdateSizersCore( false, wxALL | wxALIGN_CENTRE_VERTICAL );
@@ -230,7 +231,7 @@ void ShuttleGuiBase::AddUnits(const wxString &Prompt)
if( mShuttleMode != eIsCreating )
return;
miProp=1;
mpWind = new wxStaticText(mpParent, -1, Prompt, wxDefaultPosition, wxDefaultSize,
mpWind = safenew wxStaticText(GetParent(), -1, Prompt, wxDefaultPosition, wxDefaultSize,
Style( wxALIGN_LEFT ));
mpWind->SetName(Prompt); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
UpdateSizersCore( false, wxALL | wxALIGN_LEFT );
@@ -243,7 +244,7 @@ void ShuttleGuiBase::AddTitle(const wxString &Prompt)
return;
if( mShuttleMode != eIsCreating )
return;
mpWind = new wxStaticText(mpParent, -1, Prompt, wxDefaultPosition, wxDefaultSize,
mpWind = safenew wxStaticText(GetParent(), -1, Prompt, wxDefaultPosition, wxDefaultSize,
Style( wxALIGN_CENTRE ));
mpWind->SetName(Prompt); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
UpdateSizers();
@@ -268,7 +269,7 @@ wxCheckBox * ShuttleGuiBase::AddCheckBox( const wxString &Prompt, const wxString
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxCheckBox);
wxCheckBox * pCheckBox;
miProp=0;
mpWind = pCheckBox = new wxCheckBox(mpParent, miId, Prompt, wxDefaultPosition, wxDefaultSize,
mpWind = pCheckBox = safenew wxCheckBox(GetParent(), miId, Prompt, wxDefaultPosition, wxDefaultSize,
Style( 0 ));
pCheckBox->SetValue(Selected == wxT("true"));
pCheckBox->SetName(wxStripMenuCodes(Prompt));
@@ -287,7 +288,7 @@ wxCheckBox * ShuttleGuiBase::AddCheckBoxOnRight( const wxString &Prompt, const w
wxCheckBox * pCheckBox;
miProp=0;
AddPrompt( Prompt );
mpWind = pCheckBox = new wxCheckBox(mpParent, miId, wxT(""), wxDefaultPosition, wxDefaultSize,
mpWind = pCheckBox = safenew wxCheckBox(GetParent(), miId, wxT(""), wxDefaultPosition, wxDefaultSize,
Style( 0 ));
pCheckBox->SetValue(Selected==wxT("true"));
pCheckBox->SetName(wxStripMenuCodes(Prompt));
@@ -301,7 +302,7 @@ wxButton * ShuttleGuiBase::AddButton(const wxString &Text, int PositionFlags)
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxButton);
wxButton * pBtn;
mpWind = pBtn = new wxButton( mpParent, miId, Text, wxDefaultPosition, wxDefaultSize,
mpWind = pBtn = safenew wxButton(GetParent(), miId, Text, wxDefaultPosition, wxDefaultSize,
Style( 0 ) );
mpWind->SetName(wxStripMenuCodes(Text));
miProp=0;
@@ -315,7 +316,7 @@ wxBitmapButton * ShuttleGuiBase::AddBitmapButton(const wxBitmap &Bitmap, int Pos
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxBitmapButton);
wxBitmapButton * pBtn;
mpWind = pBtn = new wxBitmapButton( mpParent, miId, Bitmap,
mpWind = pBtn = safenew wxBitmapButton(GetParent(), miId, Bitmap,
wxDefaultPosition, wxDefaultSize, Style( wxNO_BORDER ) );
pBtn->SetBackgroundColour(
wxColour( 246,246,243));
@@ -334,8 +335,8 @@ wxChoice * ShuttleGuiBase::AddChoice( const wxString &Prompt, const wxString &Se
miProp=0;
AddPrompt( Prompt );
mpWind = pChoice = new wxChoice(
mpParent,
mpWind = pChoice = safenew wxChoice(
GetParent(),
miId,
wxDefaultPosition,
wxDefaultSize,
@@ -355,7 +356,7 @@ void ShuttleGuiBase::AddFixedText(const wxString &Str, bool bCenter)
UseUpId();
if( mShuttleMode != eIsCreating )
return;
mpWind = new wxStaticText(mpParent, miId, Str, wxDefaultPosition, wxDefaultSize,
mpWind = safenew wxStaticText(GetParent(), miId, Str, wxDefaultPosition, wxDefaultSize,
Style( wxALIGN_LEFT ));
mpWind->SetName(wxStripMenuCodes(Str)); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
if( bCenter )
@@ -374,7 +375,7 @@ wxStaticText * ShuttleGuiBase::AddVariableText(const wxString &Str, bool bCenter
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxStaticText);
wxStaticText *pStatic;
mpWind = pStatic = new wxStaticText(mpParent, miId, Str, wxDefaultPosition, wxDefaultSize,
mpWind = pStatic = safenew wxStaticText(GetParent(), miId, Str, wxDefaultPosition, wxDefaultSize,
Style( wxALIGN_LEFT ));
mpWind->SetName(wxStripMenuCodes(Str)); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
if( bCenter )
@@ -412,7 +413,7 @@ wxComboBox * ShuttleGuiBase::AddCombo( const wxString &Prompt, const wxString &S
AddPrompt( Prompt );
mpWind = pCombo = new wxComboBox(mpParent, miId, Selected, wxDefaultPosition, wxDefaultSize,
mpWind = pCombo = safenew wxComboBox(GetParent(), miId, Selected, wxDefaultPosition, wxDefaultSize,
n, Choices, Style( style ));
mpWind->SetName(wxStripMenuCodes(Prompt));
@@ -429,7 +430,7 @@ wxRadioButton * ShuttleGuiBase::AddRadioButton(const wxString &Prompt)
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxRadioButton);
wxRadioButton * pRad;
mpWind = pRad = new wxRadioButton( mpParent, miId, Prompt,
mpWind = pRad = safenew wxRadioButton(GetParent(), miId, Prompt,
wxDefaultPosition, wxDefaultSize, Style( wxRB_GROUP ) );
mpWind->SetName(wxStripMenuCodes(Prompt));
pRad->SetValue(true );
@@ -443,7 +444,7 @@ wxRadioButton * ShuttleGuiBase::AddRadioButtonToGroup(const wxString &Prompt)
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxRadioButton);
wxRadioButton * pRad;
mpWind = pRad = new wxRadioButton( mpParent, miId, Prompt,
mpWind = pRad = safenew wxRadioButton(GetParent(), miId, Prompt,
wxDefaultPosition, wxDefaultSize, Style( 0 ) );
mpWind->SetName(wxStripMenuCodes(Prompt));
UpdateSizers();
@@ -457,7 +458,7 @@ wxSlider * ShuttleGuiBase::AddSlider(const wxString &Prompt, int pos, int Max, i
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxSlider);
AddPrompt( Prompt );
wxSlider * pSlider;
mpWind = pSlider = new wxSlider( mpParent, miId,
mpWind = pSlider = safenew wxSlider(GetParent(), miId,
pos, Min, Max,
wxDefaultPosition, wxDefaultSize,
Style( wxSL_HORIZONTAL | wxSL_LABELS | wxSL_AUTOTICKS )
@@ -475,7 +476,7 @@ wxSpinCtrl * ShuttleGuiBase::AddSpinCtrl(const wxString &Prompt, int Value, int
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxSpinCtrl);
AddPrompt( Prompt );
wxSpinCtrl * pSpinCtrl;
mpWind = pSpinCtrl = new wxSpinCtrl( mpParent, miId,
mpWind = pSpinCtrl = safenew wxSpinCtrl(GetParent(), miId,
wxEmptyString,
wxDefaultPosition, wxDefaultSize,
Style( wxSP_VERTICAL | wxSP_ARROW_KEYS ),
@@ -508,7 +509,7 @@ wxTextCtrl * ShuttleGuiBase::AddTextBox(const wxString &Caption, const wxString
long flags = wxTE_LEFT;
#endif
mpWind = pTextCtrl = new wxTextCtrl(mpParent, miId, Value,
mpWind = pTextCtrl = safenew wxTextCtrl(GetParent(), miId, Value,
wxDefaultPosition, Size, Style( flags ));
mpWind->SetName(wxStripMenuCodes(Caption));
UpdateSizers();
@@ -536,7 +537,7 @@ wxTextCtrl * ShuttleGuiBase::AddNumericTextBox(const wxString &Caption, const wx
#endif
wxTextValidator Validator(wxFILTER_NUMERIC);
mpWind = pTextCtrl = new wxTextCtrl(mpParent, miId, Value,
mpWind = pTextCtrl = safenew wxTextCtrl(GetParent(), miId, Value,
wxDefaultPosition, Size, Style( flags ),
Validator // It's OK to pass this. It will be cloned.
);
@@ -553,7 +554,7 @@ wxTextCtrl * ShuttleGuiBase::AddTextWindow(const wxString &Value)
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxTextCtrl);
wxTextCtrl * pTextCtrl;
SetProportions( 1 );
mpWind = pTextCtrl = new wxTextCtrl(mpParent, miId, Value,
mpWind = pTextCtrl = safenew wxTextCtrl(GetParent(), miId, Value,
wxDefaultPosition, wxDefaultSize, Style( wxTE_MULTILINE ));
UpdateSizers();
// Start off at start of window...
@@ -573,7 +574,7 @@ void ShuttleGuiBase::AddConstTextBox(const wxString &Prompt, const wxString &Val
AddPrompt( Prompt );
UpdateSizers();
miProp=0;
mpWind = new wxStaticText(mpParent, miId, Value, wxDefaultPosition, wxDefaultSize,
mpWind = safenew wxStaticText(GetParent(), miId, Value, wxDefaultPosition, wxDefaultSize,
Style( 0 ));
mpWind->SetName(Value); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
UpdateSizers();
@@ -586,7 +587,7 @@ wxListBox * ShuttleGuiBase::AddListBox(const wxArrayString * pChoices, long styl
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxListBox);
wxListBox * pListBox;
SetProportions( 1 );
mpWind = pListBox = new wxListBox(mpParent, miId,
mpWind = pListBox = safenew wxListBox(GetParent(), miId,
wxDefaultPosition, wxDefaultSize,*pChoices, style);
pListBox->SetMinSize( wxSize( 120,150 ));
UpdateSizers();
@@ -601,7 +602,7 @@ wxListCtrl * ShuttleGuiBase::AddListControl()
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxListCtrl);
wxListCtrl * pListCtrl;
SetProportions( 1 );
mpWind = pListCtrl = new wxListCtrl(mpParent, miId,
mpWind = pListCtrl = safenew wxListCtrl(GetParent(), miId,
wxDefaultPosition, wxDefaultSize, Style( wxLC_ICON ));
pListCtrl->SetMinSize( wxSize( 120,150 ));
UpdateSizers();
@@ -615,7 +616,7 @@ wxGrid * ShuttleGuiBase::AddGrid()
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxGrid);
wxGrid * pGrid;
SetProportions( 1 );
mpWind = pGrid = new wxGrid(mpParent, miId, wxDefaultPosition,
mpWind = pGrid = safenew wxGrid(GetParent(), miId, wxDefaultPosition,
wxDefaultSize, Style( wxWANTS_CHARS ));
pGrid->SetMinSize( wxSize( 120, 150 ));
UpdateSizers();
@@ -629,7 +630,7 @@ wxListCtrl * ShuttleGuiBase::AddListControlReportMode()
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxListCtrl);
wxListCtrl * pListCtrl;
SetProportions( 1 );
mpWind = pListCtrl = new wxListCtrl(mpParent, miId,
mpWind = pListCtrl = safenew wxListCtrl(GetParent(), miId,
wxDefaultPosition, wxSize(230,120),//wxDefaultSize,
Style( wxLC_REPORT | wxLC_HRULES | wxLC_VRULES | wxSUNKEN_BORDER ));
// pListCtrl->SetMinSize( wxSize( 120,150 ));
@@ -644,7 +645,7 @@ wxTreeCtrl * ShuttleGuiBase::AddTree()
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxTreeCtrl);
wxTreeCtrl * pTreeCtrl;
SetProportions( 1 );
mpWind = pTreeCtrl = new wxTreeCtrl(mpParent, miId, wxDefaultPosition, wxDefaultSize,
mpWind = pTreeCtrl = safenew wxTreeCtrl(GetParent(), miId, wxDefaultPosition, wxDefaultSize,
Style( wxTR_HAS_BUTTONS ));
pTreeCtrl->SetMinSize( wxSize( 120,650 ));
UpdateSizers();
@@ -658,7 +659,7 @@ void ShuttleGuiBase::AddIcon(wxBitmap *pBmp)
// return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wx);
return;
wxBitmapButton * pBtn;
mpWind = pBtn = new wxBitmapButton( mpParent, miId, *pBmp,
mpWind = pBtn = safenew wxBitmapButton(GetParent(), miId, *pBmp,
wxDefaultPosition, wxDefaultSize, Style( wxBU_AUTODRAW ) );
pBtn->SetWindowStyle( 0 );
UpdateSizersC();
@@ -702,7 +703,7 @@ wxStaticBox * ShuttleGuiBase::StartStatic(const wxString &Str, int iProp)
mBoxName = Str;
if( mShuttleMode != eIsCreating )
return NULL;
wxStaticBox * pBox = new wxStaticBox(mpParent, miId,
wxStaticBox * pBox = safenew wxStaticBox(GetParent(), miId,
Str );
pBox->SetLabel( Str );
pBox->SetName(wxStripMenuCodes(Str));
@@ -736,7 +737,7 @@ wxScrolledWindow * ShuttleGuiBase::StartScroller(int iStyle)
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxScrolledWindow);
wxScrolledWindow * pScroller;
mpWind = pScroller = new wxScrolledWindow( mpParent, miId, wxDefaultPosition, wxDefaultSize,
mpWind = pScroller = safenew wxScrolledWindow(GetParent(), miId, wxDefaultPosition, wxDefaultSize,
Style( wxSUNKEN_BORDER ) );
pScroller->SetScrollRate( 20,20 );
@@ -792,7 +793,7 @@ wxPanel * ShuttleGuiBase::StartPanel(int iStyle)
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxPanel);
wxPanel * pPanel;
mpWind = pPanel = new wxPanel( mpParent, miId, wxDefaultPosition, wxDefaultSize,
mpWind = pPanel = safenew wxPanel( GetParent(), miId, wxDefaultPosition, wxDefaultSize,
Style( wxNO_BORDER ));
if( iStyle != 0 )
@@ -829,7 +830,7 @@ wxNotebook * ShuttleGuiBase::StartNotebook()
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxNotebook);
wxNotebook * pNotebook;
mpWind = pNotebook = new wxNotebook(mpParent,
mpWind = pNotebook = safenew wxNotebook(GetParent(),
miId, wxDefaultPosition, wxDefaultSize, Style( 0 ));
SetProportions( 1 );
UpdateSizers();
@@ -850,7 +851,7 @@ wxNotebookPage * ShuttleGuiBase::StartNotebookPage( const wxString & Name )
return NULL;
// return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wx);
wxNotebook * pNotebook = (wxNotebook*)mpParent;
wxNotebookPage * pPage = new wxPanel(mpParent );
wxNotebookPage * pPage = safenew wxPanel(GetParent());
pPage->SetName(Name);
pNotebook->AddPage(
@@ -873,7 +874,7 @@ void ShuttleGuiBase::StartNotebookPage( const wxString & Name, wxNotebookPage *
return;
// return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wx);
wxNotebook * pNotebook = (wxNotebook*)mpParent;
// wxNotebookPage * pPage = new wxPanel(mpParent );
// wxNotebookPage * pPage = safenew wxPanel(GetParent());
pPage->Create( mpParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, wxT("panel"));
pPage->SetName(Name);
@@ -937,7 +938,7 @@ wxPanel * ShuttleGuiBase::StartInvisiblePanel()
if( mShuttleMode != eIsCreating )
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxPanel);
wxPanel * pPanel;
mpWind = pPanel = new wxPanel( mpParent, miId, wxDefaultPosition, wxDefaultSize,
mpWind = pPanel = safenew wxPanel(GetParent(), miId, wxDefaultPosition, wxDefaultSize,
wxNO_BORDER);
mpWind->SetBackgroundColour(
@@ -1343,7 +1344,7 @@ wxRadioButton * ShuttleGuiBase::TieRadioButton(const wxString &Prompt, WrappedTy
{
case eIsCreating:
{
mpWind = pRadioButton = new wxRadioButton( mpParent, miId, Prompt,
mpWind = pRadioButton = safenew wxRadioButton(GetParent(), miId, Prompt,
wxDefaultPosition, wxDefaultSize,
(mRadioCount==1)?wxRB_GROUP:0);
pRadioButton->SetValue(WrappedRef.ValuesMatch( mRadioValue ));
@@ -2117,77 +2118,80 @@ AttachableScrollBar * ShuttleGui::AddAttachableScrollBar( long style )
wxSizer *CreateStdButtonSizer(wxWindow *parent, long buttons, wxWindow *extra)
{
wxButton *b = new wxButton( parent, 0, wxEmptyString );
wxASSERT(parent != NULL); // To justify safenew
int margin;
{
#if defined(__WXMAC__)
margin = 12;
margin = 12;
#elif defined(__WXGTK20__)
margin = 12;
margin = 12;
#elif defined(__WXMSW__)
margin = b->ConvertDialogToPixels( wxSize( 2, 0 ) ).x;
wxButton b(parent, 0, wxEmptyString);
margin = b.ConvertDialogToPixels(wxSize(2, 0)).x;
#else
margin = b->ConvertDialogToPixels( wxSize( 4, 0 ) ).x;
wxButton b(parent, 0, wxEmptyString);
margin = b->ConvertDialogToPixels(wxSize(4, 0)).x;
#endif
}
delete b;
wxButton *b = NULL;
wxStdDialogButtonSizer *bs = new wxStdDialogButtonSizer();
if( buttons & eOkButton )
{
b = new wxButton( parent, wxID_OK );
b = safenew wxButton(parent, wxID_OK);
b->SetDefault();
bs->AddButton( b );
}
if( buttons & eCancelButton )
{
bs->AddButton( new wxButton( parent, wxID_CANCEL ) );
bs->AddButton(safenew wxButton(parent, wxID_CANCEL));
}
if( buttons & eYesButton )
{
b = new wxButton( parent, wxID_YES );
b = safenew wxButton(parent, wxID_YES);
b->SetDefault();
bs->AddButton( b );
}
if( buttons & eNoButton )
{
bs->AddButton( new wxButton( parent, wxID_NO ) );
bs->AddButton(safenew wxButton(parent, wxID_NO));
}
if( buttons & eApplyButton )
{
b = new wxButton( parent, wxID_APPLY );
b = safenew wxButton(parent, wxID_APPLY);
b->SetDefault();
bs->AddButton( b );
}
if( buttons & eCloseButton )
{
bs->AddButton( new wxButton( parent, wxID_CANCEL, _("&Close") ) );
bs->AddButton(safenew wxButton(parent, wxID_CANCEL, _("&Close")));
}
if( buttons & eHelpButton )
{
bs->AddButton( new wxButton( parent, wxID_HELP ) );
bs->AddButton(safenew wxButton(parent, wxID_HELP));
}
if (buttons & ePreviewButton)
{
bs->Add( new wxButton( parent, ePreviewID, _("Pre&view") ), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin );
bs->Add(safenew wxButton(parent, ePreviewID, _("Pre&view")), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin);
}
if (buttons & ePreviewDryButton)
{
bs->Add(new wxButton( parent, ePreviewDryID, _("Dry Previe&w") ), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin );
bs->Add(safenew wxButton(parent, ePreviewDryID, _("Dry Previe&w")), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin);
bs->Add( 20, 0 );
}
if( buttons & eSettingsButton )
{
bs->Add(new wxButton( parent, eSettingsID, _("&Settings") ), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin );
bs->Add(safenew wxButton(parent, eSettingsID, _("&Settings")), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin);
bs->Add( 20, 0 );
}
@@ -2218,7 +2222,7 @@ wxSizer *CreateStdButtonSizer(wxWindow *parent, long buttons, wxWindow *extra)
}
}
b = new wxButton( parent, eDebugID, _("Debu&g") );
b = safenew wxButton(parent, eDebugID, _("Debu&g"));
bs->Insert( lastLastSpacer + 1, b, 0, wxALIGN_CENTER | wxLEFT | wxRIGHT, margin );
}