Bugs 895, 1048: Now typing '-' can set upper or lower frequency to undefined
This commit is contained in:
parent
d3c9a9fd80
commit
7f7506dbcd
|
@ -158,12 +158,14 @@ void SpectralSelectionBar::Populate()
|
|||
|
||||
mLowCtrl = new NumericTextCtrl(
|
||||
NumericConverter::FREQUENCY, this, OnLowID, frequencyFormatName, 0.0);
|
||||
mLowCtrl->SetInvalidValue(SelectedRegion::UndefinedFrequency);
|
||||
mLowCtrl->SetName(_("Low Frequency:"));
|
||||
mLowCtrl->EnableMenu();
|
||||
subSizer->Add(mLowCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 5);
|
||||
|
||||
mHighCtrl = new NumericTextCtrl(
|
||||
NumericConverter::FREQUENCY, this, OnHighID, frequencyFormatName, 0.0);
|
||||
mHighCtrl->SetInvalidValue(SelectedRegion::UndefinedFrequency);
|
||||
mHighCtrl->SetName(wxString(_("High Frequency:")));
|
||||
mHighCtrl->EnableMenu();
|
||||
subSizer->Add(mHighCtrl, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 0);
|
||||
|
|
|
@ -533,6 +533,7 @@ NumericConverter::NumericConverter(Type type,
|
|||
{
|
||||
ResetMinValue();
|
||||
ResetMaxValue();
|
||||
mInvalidValue = -1.0;
|
||||
|
||||
mDefaultNdx = 0;
|
||||
|
||||
|
@ -866,7 +867,7 @@ void NumericConverter::ControlsToValue()
|
|||
|
||||
if (mFields.GetCount() > 0 &&
|
||||
mValueString.Mid(mFields[0].pos, 1) == wxChar('-')) {
|
||||
mValue = -1;
|
||||
mValue = mInvalidValue;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1169,6 +1170,7 @@ NumericTextCtrl::NumericTextCtrl(NumericConverter::Type type,
|
|||
mAutoPos(autoPos)
|
||||
, mType(type)
|
||||
{
|
||||
mAllowInvalidValue = false;
|
||||
|
||||
mDigitBoxW = 10;
|
||||
mDigitBoxH = 16;
|
||||
|
@ -1211,6 +1213,7 @@ NumericTextCtrl::~NumericTextCtrl()
|
|||
|
||||
// Set the focus to the first (left-most) non-zero digit
|
||||
// If all digits are zero, the right-most position is focused
|
||||
// If all digits are hyphens (invalid), the left-most position is focused
|
||||
void NumericTextCtrl::UpdateAutoFocus()
|
||||
{
|
||||
if (!mAutoPos)
|
||||
|
@ -1280,6 +1283,15 @@ void NumericTextCtrl::EnableMenu(bool enable)
|
|||
Fit();
|
||||
}
|
||||
|
||||
void NumericTextCtrl::SetInvalidValue(double invalidValue)
|
||||
{
|
||||
const bool wasInvalid = mAllowInvalidValue && (mValue == mInvalidValue);
|
||||
mAllowInvalidValue = true;
|
||||
mInvalidValue = invalidValue;
|
||||
if (wasInvalid)
|
||||
SetValue(invalidValue);
|
||||
}
|
||||
|
||||
bool NumericTextCtrl::Layout()
|
||||
{
|
||||
unsigned int i, j;
|
||||
|
@ -1596,6 +1608,7 @@ void NumericTextCtrl::OnCaptureKey(wxCommandEvent &event)
|
|||
case WXK_TAB:
|
||||
case WXK_RETURN:
|
||||
case WXK_NUMPAD_ENTER:
|
||||
case '-':
|
||||
return;
|
||||
|
||||
default:
|
||||
|
@ -1618,6 +1631,7 @@ void NumericTextCtrl::OnKeyUp(wxKeyEvent &event)
|
|||
keyCode -= WXK_NUMPAD0 - '0';
|
||||
|
||||
if ((keyCode >= '0' && keyCode <= '9') ||
|
||||
(keyCode == '-') ||
|
||||
(keyCode == WXK_BACK) ||
|
||||
(keyCode == WXK_UP) ||
|
||||
(keyCode == WXK_DOWN)) {
|
||||
|
@ -1661,6 +1675,11 @@ void NumericTextCtrl::OnKeyDown(wxKeyEvent &event)
|
|||
Updated();
|
||||
}
|
||||
|
||||
else if (!mReadOnly && keyCode == '-') {
|
||||
if (mAllowInvalidValue)
|
||||
SetValue(mInvalidValue);
|
||||
}
|
||||
|
||||
else if (!mReadOnly && keyCode == WXK_BACK) {
|
||||
// Moves left, replaces that char with '0', stays there...
|
||||
mFocusedDigit--;
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
void ResetMinValue();
|
||||
void SetMaxValue(double maxValue);
|
||||
void ResetMaxValue();
|
||||
|
||||
double GetValue();
|
||||
|
||||
wxString GetString();
|
||||
|
@ -101,6 +102,7 @@ protected:
|
|||
|
||||
double mMinValue;
|
||||
double mMaxValue;
|
||||
double mInvalidValue;
|
||||
|
||||
wxString mFormatString;
|
||||
|
||||
|
@ -154,6 +156,12 @@ class NumericTextCtrl: public wxControl, public NumericConverter
|
|||
void SetReadOnly(bool readOnly = true);
|
||||
void EnableMenu(bool enable = true);
|
||||
|
||||
// The text control permits typing '-' to make the value invalid only if this
|
||||
// function has previously been called.
|
||||
// Maybe you want something other than the default of -1 to indicate the invalid value
|
||||
// this control returns to the program, so you can specify.
|
||||
void SetInvalidValue(double invalidValue);
|
||||
|
||||
int GetFocusedField() { return mLastField; }
|
||||
int GetFocusedDigit() { return mFocusedDigit; }
|
||||
|
||||
|
@ -207,6 +215,8 @@ private:
|
|||
|
||||
NumericConverter::Type mType;
|
||||
|
||||
bool mAllowInvalidValue;
|
||||
|
||||
DECLARE_EVENT_TABLE()
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user