NumericTextControl ctor arguments...

... follow wxWidgets conventions for first two arguments; add Options
This commit is contained in:
Paul Licameli 2017-10-27 19:14:48 -04:00
parent 517bdf1ba8
commit 5724780be9
16 changed files with 146 additions and 157 deletions

View File

@ -56,17 +56,15 @@ void TimeDialog::PopulateOrExchange(ShuttleGui &S)
{
mTimeCtrl = safenew
NumericTextCtrl(
NumericConverter::TIME, this,
wxID_ANY,
this, wxID_ANY,
NumericConverter::TIME,
mFormat,
mTime,
mRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl::Options{}
.AutoPos(true));
mTimeCtrl->SetName(mPrompt);
S.AddWindow(mTimeCtrl);
mTimeCtrl->EnableMenu();
}
S.EndStatic();
}

View File

@ -793,6 +793,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* displayed is minutes, and the 's' indicates that the third number displayed is seconds.
*/
wxString strFormat = _("099 h 060 m 060 s");
const auto options = NumericTextCtrl::Options{}.MenuEnabled(false);
S.StartStatic(_("Start Date and Time"), true);
{
m_pDatePickerCtrl_Start =
@ -808,13 +809,13 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.AddWindow(m_pDatePickerCtrl_Start);
m_pTimeTextCtrl_Start = safenew NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_START);
this, ID_TIMETEXT_START, NumericConverter::TIME,
wxEmptyString, 0, 44100, options);
m_pTimeTextCtrl_Start->SetName(_("Start Time"));
m_pTimeTextCtrl_Start->SetFormatString(strFormat);
m_pTimeTextCtrl_Start->
SetValue(wxDateTime_to_AudacityTime(m_DateTime_Start));
S.AddWindow(m_pTimeTextCtrl_Start);
m_pTimeTextCtrl_Start->EnableMenu(false);
}
S.EndStatic();
@ -836,12 +837,12 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.AddWindow(m_pDatePickerCtrl_End);
m_pTimeTextCtrl_End = safenew NumericTextCtrl(
NumericConverter::TIME, this, ID_TIMETEXT_END);
this, ID_TIMETEXT_END, NumericConverter::TIME,
wxEmptyString, 0, 44100, options);
m_pTimeTextCtrl_End->SetName(_("End Time"));
m_pTimeTextCtrl_End->SetFormatString(strFormat);
m_pTimeTextCtrl_End->SetValue(wxDateTime_to_AudacityTime(m_DateTime_End));
S.AddWindow(m_pTimeTextCtrl_End);
m_pTimeTextCtrl_End->EnableMenu(false);
}
S.EndStatic();
@ -856,12 +857,13 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
* seconds.
*/
wxString strFormat1 = _("099 days 024 h 060 m 060 s");
m_pTimeTextCtrl_Duration = safenew NumericTextCtrl(NumericConverter::TIME, this, ID_TIMETEXT_DURATION);
m_pTimeTextCtrl_Duration = safenew NumericTextCtrl(
this, ID_TIMETEXT_DURATION, NumericConverter::TIME,
wxEmptyString, 0, 44100, options);
m_pTimeTextCtrl_Duration->SetName(_("Duration"));
m_pTimeTextCtrl_Duration->SetFormatString(strFormat1);
m_pTimeTextCtrl_Duration->SetValue(m_TimeSpan_Duration.GetSeconds().ToDouble());
S.AddWindow(m_pTimeTextCtrl_Duration);
m_pTimeTextCtrl_Duration->EnableMenu(false);
}
S.EndStatic();
}

View File

@ -369,31 +369,29 @@ void EffectChangeSpeed::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(_("Current Length:"));
mpFromLengthCtrl = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
wxID_ANY,
NumericTextCtrl(S.GetParent(), wxID_ANY,
NumericConverter::TIME,
mFormat,
mFromLength,
mProjectRate);
mProjectRate,
NumericTextCtrl::Options{}
.ReadOnly(true)
.MenuEnabled(false));
mpFromLengthCtrl->SetName(_("from"));
mpFromLengthCtrl->SetToolTip(_("Current length of selection."));
mpFromLengthCtrl->SetReadOnly(true);
mpFromLengthCtrl->EnableMenu(false);
S.AddWindow(mpFromLengthCtrl, wxALIGN_LEFT);
S.AddPrompt(_("New Length:"));
mpToLengthCtrl = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
ID_ToLength,
NumericTextCtrl(S.GetParent(), ID_ToLength,
NumericConverter::TIME,
mFormat,
mToLength,
mProjectRate);
mpToLengthCtrl->SetName(_("to"));
mpToLengthCtrl->EnableMenu();
S.AddWindow(mpToLengthCtrl, wxALIGN_LEFT);
}
S.EndMultiColumn();

View File

@ -200,39 +200,36 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
S.AddFixedText( {} ); // spacer
S.AddFixedText(_("Volume "));
const auto options = NumericTextCtrl::Options{}
.AutoPos(true)
.MenuEnabled(false)
.ReadOnly(true);
//Foreground
S.AddFixedText(_("&Foreground:"), false);
if (S.GetMode() == eIsCreating)
{
mForegroundStartT = safenew
NumericTextCtrl(NumericConverter::TIME, this,
ID_FOREGROUNDSTART_T,
NumericTextCtrl(this, ID_FOREGROUNDSTART_T,
NumericConverter::TIME,
_("hh:mm:ss + hundredths"),
0.0,
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
options);
mForegroundStartT->SetName(_("Foreground start time"));
mForegroundStartT->EnableMenu(false);
mForegroundStartT->SetReadOnly(true);
}
S.AddWindow(mForegroundStartT);
if (S.GetMode() == eIsCreating)
{
mForegroundEndT = safenew
NumericTextCtrl(NumericConverter::TIME, this,
ID_FOREGROUNDEND_T,
NumericTextCtrl(this, ID_FOREGROUNDEND_T,
NumericConverter::TIME,
_("hh:mm:ss + hundredths"),
0.0,
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
options);
mForegroundEndT->SetName(_("Foreground end time"));
mForegroundEndT->EnableMenu(false);
mForegroundEndT->SetReadOnly(true);
}
S.AddWindow(mForegroundEndT);
@ -245,34 +242,26 @@ ContrastDialog::ContrastDialog(wxWindow * parent, wxWindowID id,
if (S.GetMode() == eIsCreating)
{
mBackgroundStartT = safenew
NumericTextCtrl(NumericConverter::TIME, this,
ID_BACKGROUNDSTART_T,
NumericTextCtrl(this, ID_BACKGROUNDSTART_T,
NumericConverter::TIME,
_("hh:mm:ss + hundredths"),
0.0,
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
options);
mBackgroundStartT->SetName(_("Background start time"));
mBackgroundStartT->EnableMenu(false);
mBackgroundStartT->SetReadOnly(true);
}
S.AddWindow(mBackgroundStartT);
if (S.GetMode() == eIsCreating)
{
mBackgroundEndT = safenew
NumericTextCtrl(NumericConverter::TIME, this,
ID_BACKGROUNDEND_T,
NumericTextCtrl(this, ID_BACKGROUNDEND_T,
NumericConverter::TIME,
_("hh:mm:ss + hundredths"),
0.0,
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
options);
mBackgroundEndT->SetName(_("Background end time"));
mBackgroundEndT->EnableMenu(false);
mBackgroundEndT->SetReadOnly(true);
}
S.AddWindow(mBackgroundEndT);

View File

@ -326,17 +326,14 @@ void EffectDtmf::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(_("Duration:"));
mDtmfDurationT = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
ID_Duration,
NumericTextCtrl(S.GetParent(), ID_Duration,
NumericConverter::TIME,
GetDurationFormat(),
GetDuration(),
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl::Options{}
.AutoPos(true));
mDtmfDurationT->SetName(_("Duration"));
mDtmfDurationT->EnableMenu();
S.AddWindow(mDtmfDurationT);
S.AddFixedText(_("Tone/silence ratio:"), false);

View File

@ -231,17 +231,14 @@ void EffectNoise::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(_("Duration:"));
mNoiseDurationT = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
wxID_ANY,
NumericTextCtrl(S.GetParent(), wxID_ANY,
NumericConverter::TIME,
GetDurationFormat(),
GetDuration(),
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl::Options{}
.AutoPos(true));
mNoiseDurationT->SetName(_("Duration"));
mNoiseDurationT->EnableMenu();
S.AddWindow(mNoiseDurationT, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL);
}
S.EndMultiColumn();

View File

@ -65,17 +65,14 @@ void EffectSilence::PopulateOrExchange(ShuttleGui & S)
{
S.AddPrompt(_("Duration:"));
mDurationT = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
wxID_ANY,
NumericTextCtrl(S.GetParent(), wxID_ANY,
NumericConverter::TIME,
GetDurationFormat(),
GetDuration(),
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
mProjectRate,
NumericTextCtrl::Options{}
.AutoPos(true));
mDurationT->SetName(_("Duration"));
mDurationT->EnableMenu();
S.AddWindow(mDurationT, wxALIGN_CENTER | wxALL);
}
S.EndHorizontalLay();

View File

@ -406,17 +406,14 @@ void EffectToneGen::PopulateOrExchange(ShuttleGui & S)
S.AddPrompt(_("Duration:"));
mToneDurationT = safenew
NumericTextCtrl(NumericConverter::TIME,
S.GetParent(),
wxID_ANY,
NumericTextCtrl(S.GetParent(), wxID_ANY,
NumericConverter::TIME,
GetDurationFormat(),
GetDuration(),
mProjectRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl::Options{}
.AutoPos(true));
mToneDurationT->SetName(_("Duration"));
mToneDurationT->EnableMenu();
S.AddWindow(mToneDurationT, wxALIGN_LEFT | wxALL);
}
S.EndMultiColumn();

View File

@ -2836,17 +2836,14 @@ void VSTEffect::BuildPlain()
wxControl *item = safenew wxStaticText(scroller, 0, _("Duration:"));
gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
mDuration = safenew
NumericTextCtrl(NumericConverter::TIME,
scroller,
ID_Duration,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl(scroller, ID_Duration,
NumericConverter::TIME,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
NumericTextCtrl::Options{}
.AutoPos(true));
mDuration->SetName(_("Duration"));
mDuration->EnableMenu();
gridSizer->Add(mDuration, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
gridSizer->Add(1, 1, 0);
gridSizer->Add(1, 1, 0);

View File

@ -1210,17 +1210,14 @@ bool LadspaEffect::PopulateUI(wxWindow *parent)
item = safenew wxStaticText(w, 0, _("Duration:"));
gridSizer->Add(item, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
mDuration = safenew
NumericTextCtrl(NumericConverter::TIME,
w,
ID_Duration,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl(w, ID_Duration,
NumericConverter::TIME,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
NumericTextCtrl::Options{}
.AutoPos(true));
mDuration->SetName(_("Duration"));
mDuration->EnableMenu();
gridSizer->Add(mDuration, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
gridSizer->Add(1, 1, 0);
gridSizer->Add(1, 1, 0);

View File

@ -1566,17 +1566,14 @@ bool LV2Effect::BuildPlain()
wxWindow *item = safenew wxStaticText(w, 0, _("&Duration:"));
sizer->Add(item, 0, wxALIGN_CENTER | wxALL, 5);
mDuration = safenew
NumericTextCtrl(NumericConverter::TIME,
w,
ID_Duration,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
wxDefaultPosition,
wxDefaultSize,
true);
NumericTextCtrl(w, ID_Duration,
NumericConverter::TIME,
mHost->GetDurationFormat(),
mHost->GetDuration(),
mSampleRate,
NumericTextCtrl::Options{}
.AutoPos(true));
mDuration->SetName(_("Duration"));
mDuration->EnableMenu();
sizer->Add(mDuration, 0, wxALIGN_CENTER | wxALL, 5);
groupSizer->Add(sizer.release(), 0, wxALIGN_CENTER | wxALL, 5);

View File

@ -205,10 +205,9 @@ auStaticText * SelectionBar::AddTitle( const wxString & Title, wxSizer * pSizer
NumericTextCtrl * SelectionBar::AddTime( const wxString Name, int id, wxSizer * pSizer ){
wxString formatName = mListener ? mListener->AS_GetSelectionFormat()
: wxString(wxEmptyString);
NumericTextCtrl * pCtrl = safenew NumericTextCtrl(
NumericConverter::TIME, this, id, formatName, 0.0, mRate);
auto pCtrl = safenew NumericTextCtrl(
this, id, NumericConverter::TIME, formatName, 0.0, mRate);
pCtrl->SetName(Name);
pCtrl->EnableMenu();
pSizer->Add(pCtrl, 0, wxALIGN_TOP | wxRIGHT, 5);
return pCtrl;
}

View File

@ -166,31 +166,39 @@ void SpectralSelectionBar::Populate()
auto subSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
mCenterCtrl = safenew NumericTextCtrl(
NumericConverter::FREQUENCY, this, OnCenterID, frequencyFormatName, 0.0);
mCenterCtrl->SetInvalidValue(SelectedRegion::UndefinedFrequency);
this, OnCenterID,
NumericConverter::FREQUENCY, frequencyFormatName, 0.0, 44100.0,
NumericTextCtrl::Options{}
.InvalidValue( true, SelectedRegion::UndefinedFrequency )
);
mCenterCtrl->SetName(_("Center Frequency:"));
mCenterCtrl->EnableMenu();
subSizer->Add(mCenterCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mWidthCtrl = safenew NumericTextCtrl(
NumericConverter::BANDWIDTH, this, OnWidthID, bandwidthFormatName, 0.0);
mWidthCtrl->SetInvalidValue(-1.0);
this, OnWidthID,
NumericConverter::BANDWIDTH, bandwidthFormatName, 0.0, 44100.0,
NumericTextCtrl::Options{}
.InvalidValue( true, -1.0 )
);
mWidthCtrl->SetName(wxString(_("Bandwidth:")));
mWidthCtrl->EnableMenu();
subSizer->Add(mWidthCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mLowCtrl = safenew NumericTextCtrl(
NumericConverter::FREQUENCY, this, OnLowID, frequencyFormatName, 0.0);
mLowCtrl->SetInvalidValue(SelectedRegion::UndefinedFrequency);
this, OnLowID,
NumericConverter::FREQUENCY, frequencyFormatName, 0.0, 44100.0,
NumericTextCtrl::Options{}
.InvalidValue( true, SelectedRegion::UndefinedFrequency )
);
mLowCtrl->SetName(_("Low Frequency:"));
mLowCtrl->EnableMenu();
subSizer->Add(mLowCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mHighCtrl = safenew NumericTextCtrl(
NumericConverter::FREQUENCY, this, OnHighID, frequencyFormatName, 0.0);
mHighCtrl->SetInvalidValue(SelectedRegion::UndefinedFrequency);
this, OnHighID,
NumericConverter::FREQUENCY, frequencyFormatName, 0.0, 44100.0,
NumericTextCtrl::Options{}
.InvalidValue( true, SelectedRegion::UndefinedFrequency )
);
mHighCtrl->SetName(wxString(_("High Frequency:")));
mHighCtrl->EnableMenu();
subSizer->Add(mHighCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
mCenterCtrl->Show(mbCenterAndWidth);

View File

@ -44,16 +44,17 @@ NumericEditor::~NumericEditor()
void NumericEditor::Create(wxWindow *parent, wxWindowID id, wxEvtHandler *handler)
{
wxASSERT(parent); // to justify safenew
auto control = safenew NumericTextCtrl(mType, parent,
wxID_ANY,
mFormat,
mOld,
mRate,
wxDefaultPosition,
wxDefaultSize,
true);
if (mType == NumericTextCtrl::FREQUENCY)
control->SetInvalidValue(SelectedRegion::UndefinedFrequency);
auto control = safenew NumericTextCtrl(
parent, wxID_ANY,
mType,
mFormat,
mOld,
mRate,
NumericTextCtrl::Options{}
.AutoPos(true)
.InvalidValue(mType == NumericTextCtrl::FREQUENCY,
SelectedRegion::UndefinedFrequency)
);
m_control = control;
wxGridCellEditor::Create(parent, id, handler);
@ -174,14 +175,13 @@ void NumericRenderer::Draw(wxGrid &grid,
table->GetValue(row, col).ToDouble(&value);
NumericTextCtrl tt(mType, &grid,
wxID_ANY,
NumericTextCtrl tt(&grid, wxID_ANY,
mType,
ne->GetFormat(),
value,
ne->GetRate(),
wxPoint(10000, 10000), // create offscreen
wxDefaultSize,
true);
NumericTextCtrl::Options{}.AutoPos(true),
wxPoint(10000, 10000)); // create offscreen
tstr = tt.GetString();
ne->DecRef();
@ -231,14 +231,13 @@ wxSize NumericRenderer::GetBestSize(wxGrid &grid,
if (ne) {
double value;
table->GetValue(row, col).ToDouble(&value);
NumericTextCtrl tt(mType, &grid,
wxID_ANY,
NumericTextCtrl tt(&grid, wxID_ANY,
mType,
ne->GetFormat(),
value,
ne->GetRate(),
wxPoint(10000, 10000), // create offscreen
wxDefaultSize,
true);
NumericTextCtrl::Options{}.AutoPos(true),
wxPoint(10000, 10000)); // create offscreen
sz = tt.GetSize();
ne->DecRef();

View File

@ -1239,22 +1239,21 @@ END_EVENT_TABLE()
IMPLEMENT_CLASS(NumericTextCtrl, wxControl)
NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
wxWindow *parent,
wxWindowID id,
NumericTextCtrl::NumericTextCtrl(wxWindow *parent, wxWindowID id,
NumericConverter::Type type,
const wxString &formatName,
double timeValue,
double sampleRate,
const Options &options,
const wxPoint &pos,
const wxSize &size,
bool autoPos):
const wxSize &size):
wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
NumericConverter(type, formatName, timeValue, sampleRate),
mBackgroundBitmap{},
mDigitFont{},
mLabelFont{},
mLastField(1),
mAutoPos(autoPos)
mAutoPos(options.autoPos)
, mType(type)
{
mAllowInvalidValue = false;
@ -1262,8 +1261,8 @@ NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
mDigitBoxW = 10;
mDigitBoxH = 16;
mReadOnly = false;
mMenuEnabled = true;
mReadOnly = options.readOnly;
mMenuEnabled = options.menuEnabled;
mButtonWidth = 9;
Layout();
@ -1282,6 +1281,9 @@ NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
SetName(wxT(""));
SetAccessible(safenew NumericTextCtrlAx(this));
#endif
if (options.hasInvalidValue)
SetInvalidValue( options.invalidValue );
}
NumericTextCtrl::~NumericTextCtrl()

View File

@ -145,15 +145,30 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
public:
DECLARE_DYNAMIC_CLASS(NumericTextCtrl)
NumericTextCtrl(NumericConverter::Type type,
wxWindow *parent,
wxWindowID id,
struct Options {
bool autoPos { false };
bool readOnly { false };
bool menuEnabled { true };
bool hasInvalidValue { false };
double invalidValue { -1.0 };
Options() {}
Options &AutoPos (bool value) { autoPos = value; return *this; }
Options &ReadOnly (bool value) { readOnly = value; return *this; }
Options &MenuEnabled (bool value) { menuEnabled = value; return *this; }
Options &InvalidValue (bool has, double value = -1.0)
{ hasInvalidValue = has, invalidValue = value; return *this; }
};
NumericTextCtrl(wxWindow *parent, wxWindowID winid,
NumericConverter::Type type,
const wxString &formatName = wxEmptyString,
double value = 0.0,
double sampleRate = 44100,
const Options &options = {},
const wxPoint &pos = wxDefaultPosition,
const wxSize &size = wxDefaultSize,
bool autoPos = false);
const wxSize &size = wxDefaultSize);
virtual ~NumericTextCtrl();