1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 08:59:28 +02:00

Fixed meany/many typo. (reported by Yuri Chornoivan)

This commit is contained in:
james.k.crook@gmail.com 2014-11-16 13:39:18 +00:00
parent 69e9d8860a
commit 2527327fd7

View File

@ -1,79 +1,79 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
// Backport from wxWidgets-3.0-rc1 // Backport from wxWidgets-3.0-rc1
// //
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: src/common/valnum.cpp // Name: src/common/valnum.cpp
// Purpose: Numeric validator classes implementation // Purpose: Numeric validator classes implementation
// Author: Vadim Zeitlin based on the submission of Fulvio Senore // Author: Vadim Zeitlin based on the submission of Fulvio Senore
// Created: 2010-11-06 // Created: 2010-11-06
// Copyright: (c) 2010 wxWidgets team // Copyright: (c) 2010 wxWidgets team
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ============================================================================ // ============================================================================
// Declarations // Declarations
// ============================================================================ // ============================================================================
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// headers // headers
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// For compilers that support precompilation, includes "wx.h". // For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h" #include "wx/wxprec.h"
#ifdef __BORLANDC__ #ifdef __BORLANDC__
#pragma hdrstop #pragma hdrstop
#endif #endif
#if wxUSE_VALIDATORS && wxUSE_TEXTCTRL #if wxUSE_VALIDATORS && wxUSE_TEXTCTRL
#ifndef WX_PRECOMP #ifndef WX_PRECOMP
#include "wx/msgdlg.h" #include "wx/msgdlg.h"
#include "wx/textctrl.h" #include "wx/textctrl.h"
#endif #endif
#include "valnum.h" #include "valnum.h"
#include "numformatter.h" #include "numformatter.h"
// ============================================================================ // ============================================================================
// wxNumValidatorBase implementation // wxNumValidatorBase implementation
// ============================================================================ // ============================================================================
BEGIN_EVENT_TABLE(wxNumValidatorBase, wxValidator)
EVT_CHAR(wxNumValidatorBase::OnChar)
EVT_KILL_FOCUS(wxNumValidatorBase::OnKillFocus)
END_EVENT_TABLE()
int wxNumValidatorBase::GetFormatFlags() const
{
int flags = wxNumberFormatter::Style_None;
if ( m_style & wxNUM_VAL_THOUSANDS_SEPARATOR )
flags |= wxNumberFormatter::Style_WithThousandsSep;
if ( m_style & wxNUM_VAL_NO_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_NoTrailingZeroes;
if ( m_style & wxNUM_VAL_ONE_TRAILING_ZERO )
flags |= wxNumberFormatter::Style_OneTrailingZero;
if ( m_style & wxNUM_VAL_TWO_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_TwoTrailingZeroes;
if ( m_style & wxNUM_VAL_THREE_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_ThreeTrailingZeroes;
return flags;
}
wxTextEntry *wxNumValidatorBase::GetTextEntry() const
{
#if wxUSE_TEXTCTRL
if ( wxTextCtrl *text = wxDynamicCast(m_validatorWindow, wxTextCtrl) )
return text;
#endif // wxUSE_TEXTCTRL
wxFAIL_MSG(wxT("Can only be used with wxTextCtrl or wxComboBox"));
return NULL;
}
BEGIN_EVENT_TABLE(wxNumValidatorBase, wxValidator)
EVT_CHAR(wxNumValidatorBase::OnChar)
EVT_KILL_FOCUS(wxNumValidatorBase::OnKillFocus)
END_EVENT_TABLE()
int wxNumValidatorBase::GetFormatFlags() const
{
int flags = wxNumberFormatter::Style_None;
if ( m_style & wxNUM_VAL_THOUSANDS_SEPARATOR )
flags |= wxNumberFormatter::Style_WithThousandsSep;
if ( m_style & wxNUM_VAL_NO_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_NoTrailingZeroes;
if ( m_style & wxNUM_VAL_ONE_TRAILING_ZERO )
flags |= wxNumberFormatter::Style_OneTrailingZero;
if ( m_style & wxNUM_VAL_TWO_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_TwoTrailingZeroes;
if ( m_style & wxNUM_VAL_THREE_TRAILING_ZEROES )
flags |= wxNumberFormatter::Style_ThreeTrailingZeroes;
return flags;
}
wxTextEntry *wxNumValidatorBase::GetTextEntry() const
{
#if wxUSE_TEXTCTRL
if ( wxTextCtrl *text = wxDynamicCast(m_validatorWindow, wxTextCtrl) )
return text;
#endif // wxUSE_TEXTCTRL
wxFAIL_MSG(wxT("Can only be used with wxTextCtrl or wxComboBox"));
return NULL;
}
bool wxNumValidatorBase::Validate(wxWindow *parent) bool wxNumValidatorBase::Validate(wxWindow *parent)
{ {
// If window is disabled, simply return // If window is disabled, simply return
@ -94,161 +94,161 @@ bool wxNumValidatorBase::Validate(wxWindow *parent)
return true; return true;
} }
void void
wxNumValidatorBase::GetCurrentValueAndInsertionPoint(wxString& val, wxNumValidatorBase::GetCurrentValueAndInsertionPoint(wxString& val,
int& pos) const int& pos) const
{ {
wxTextEntry * const control = GetTextEntry(); wxTextEntry * const control = GetTextEntry();
if ( !control ) if ( !control )
return; return;
val = control->GetValue(); val = control->GetValue();
pos = control->GetInsertionPoint(); pos = control->GetInsertionPoint();
long selFrom, selTo; long selFrom, selTo;
control->GetSelection(&selFrom, &selTo); control->GetSelection(&selFrom, &selTo);
const long selLen = selTo - selFrom; const long selLen = selTo - selFrom;
if ( selLen ) if ( selLen )
{ {
// Remove selected text because pressing a key would make it disappear. // Remove selected text because pressing a key would make it disappear.
val.erase(selFrom, selLen); val.erase(selFrom, selLen);
// And adjust the insertion point to have correct position in the new // And adjust the insertion point to have correct position in the new
// string. // string.
if ( pos > selFrom ) if ( pos > selFrom )
{ {
if ( pos >= selTo ) if ( pos >= selTo )
pos -= selLen; pos -= selLen;
else else
pos = selFrom; pos = selFrom;
} }
} }
} }
bool wxNumValidatorBase::IsMinusOk(const wxString& val, int pos) const bool wxNumValidatorBase::IsMinusOk(const wxString& val, int pos) const
{ {
// Minus is only ever accepted in the beginning of the string. // Minus is only ever accepted in the beginning of the string.
if ( pos != 0 ) if ( pos != 0 )
return false; return false;
// And then only if there is no existing minus sign there. // And then only if there is no existing minus sign there.
if ( !val.empty() && val[0] == '-' ) if ( !val.empty() && val[0] == '-' )
return false; return false;
return true; return true;
} }
void wxNumValidatorBase::OnChar(wxKeyEvent& event) void wxNumValidatorBase::OnChar(wxKeyEvent& event)
{ {
// By default we just validate this key so don't prevent the normal // By default we just validate this key so don't prevent the normal
// handling from taking place. // handling from taking place.
event.Skip(); event.Skip();
if ( !m_validatorWindow ) if ( !m_validatorWindow )
return; return;
#if wxUSE_UNICODE #if wxUSE_UNICODE
const int ch = event.GetUnicodeKey(); const int ch = event.GetUnicodeKey();
const int c = event.GetKeyCode(); const int c = event.GetKeyCode();
if ( c > WXK_START ) if ( c > WXK_START )
{ {
// It's a character without any Unicode equivalent at all, e.g. cursor // It's a character without any Unicode equivalent at all, e.g. cursor
// arrow or function key, we never filter those. // arrow or function key, we never filter those.
return; return;
} }
#else // !wxUSE_UNICODE #else // !wxUSE_UNICODE
const int ch = event.GetKeyCode(); const int ch = event.GetKeyCode();
if ( ch > WXK_DELETE ) if ( ch > WXK_DELETE )
{ {
// Not a character neither. // Not a character neither.
return; return;
} }
#endif // wxUSE_UNICODE/!wxUSE_UNICODE #endif // wxUSE_UNICODE/!wxUSE_UNICODE
// Space is an allowed thousands separator. But we don't allow user to type // Space is an allowed thousands separator. But we don't allow user to type
// it. We will add it at formatting time in OnKillFocus(). // it. We will add it at formatting time in OnKillFocus().
if ( c < WXK_SPACE || c == WXK_DELETE ) if ( c < WXK_SPACE || c == WXK_DELETE )
{ {
// Allow ASCII control characters and Delete. // Allow ASCII control characters and Delete.
return; return;
} }
// Check if this character is allowed in the current state. // Check if this character is allowed in the current state.
wxString val; wxString val;
int pos; int pos;
GetCurrentValueAndInsertionPoint(val, pos); GetCurrentValueAndInsertionPoint(val, pos);
if ( !IsCharOk(val, pos, ch) ) if ( !IsCharOk(val, pos, ch) )
{ {
if ( !wxValidator::IsSilent() ) if ( !wxValidator::IsSilent() )
wxBell(); wxBell();
// Do not skip the event in this case, stop handling it here. // Do not skip the event in this case, stop handling it here.
event.Skip(false); event.Skip(false);
} }
} }
void wxNumValidatorBase::OnKillFocus(wxFocusEvent& event) void wxNumValidatorBase::OnKillFocus(wxFocusEvent& event)
{ {
wxTextEntry * const control = GetTextEntry(); wxTextEntry * const control = GetTextEntry();
if ( !control ) if ( !control )
return; return;
// When we change the control value below, its "modified" status is reset // When we change the control value below, its "modified" status is reset
// so we need to explicitly keep it marked as modified if it was so in the // so we need to explicitly keep it marked as modified if it was so in the
// first place. // first place.
// //
// Notice that only wxTextCtrl (and not wxTextEntry) has // Notice that only wxTextCtrl (and not wxTextEntry) has
// IsModified()/MarkDirty() methods hence the need for dynamic cast. // IsModified()/MarkDirty() methods hence the need for dynamic cast.
wxTextCtrl * const text = wxDynamicCast(m_validatorWindow, wxTextCtrl); wxTextCtrl * const text = wxDynamicCast(m_validatorWindow, wxTextCtrl);
const bool wasModified = text ? text->IsModified() : false; const bool wasModified = text ? text->IsModified() : false;
control->ChangeValue(NormalizeString(control->GetValue())); control->ChangeValue(NormalizeString(control->GetValue()));
if ( wasModified ) if ( wasModified )
text->MarkDirty(); text->MarkDirty();
event.Skip(); event.Skip();
// Validate(text); // Validate(text);
} }
// ============================================================================ // ============================================================================
// wxIntegerValidatorBase implementation // wxIntegerValidatorBase implementation
// ============================================================================ // ============================================================================
wxString wxIntegerValidatorBase::ToString(LongestValueType value) const wxString wxIntegerValidatorBase::ToString(LongestValueType value) const
{ {
return wxNumberFormatter::ToString(value, GetFormatFlags()); return wxNumberFormatter::ToString(value, GetFormatFlags());
} }
bool bool
wxIntegerValidatorBase::FromString(const wxString& s, LongestValueType *value) wxIntegerValidatorBase::FromString(const wxString& s, LongestValueType *value)
{ {
return wxNumberFormatter::FromString(s, value); return wxNumberFormatter::FromString(s, value);
} }
bool bool
wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
{ {
// We may accept minus sign if we can represent negative numbers at all. // We may accept minus sign if we can represent negative numbers at all.
if ( ch == '-' ) if ( ch == '-' )
{ {
// Notice that entering '-' can make our value invalid, for example if // Notice that entering '-' can make our value invalid, for example if
// we're limited to -5..15 range and the current value is 12, then the // we're limited to -5..15 range and the current value is 12, then the
// new value would be (invalid) -12. We consider it better to let the // new value would be (invalid) -12. We consider it better to let the
// user do this because perhaps he is going to press Delete key next to // user do this because perhaps he is going to press Delete key next to
// make it -2 and forcing him to delete 1 first would be unnatural. // make it -2 and forcing him to delete 1 first would be unnatural.
// //
// TODO: It would be nice to indicate that the current control contents // TODO: It would be nice to indicate that the current control contents
// is invalid (if it's indeed going to be the case) once // is invalid (if it's indeed going to be the case) once
// wxValidator supports doing this non-intrusively. // wxValidator supports doing this non-intrusively.
return m_min < 0 && IsMinusOk(val, pos); return m_min < 0 && IsMinusOk(val, pos);
} }
// A separator is accepted if the locale allow it, the other chars must be digits // A separator is accepted if the locale allow it, the other chars must be digits
if ( ch < '0' || ch > '9' ) if ( ch < '0' || ch > '9' )
{ {
wxChar thousands; wxChar thousands;
if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousands) ) if ( wxNumberFormatter::GetThousandsSeparatorIfUsed(&thousands) )
@ -261,10 +261,10 @@ wxIntegerValidatorBase::IsCharOk(const wxString& val, int pos, wxChar ch) const
return false; return false;
} }
} }
return true; return true;
} }
bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
{ {
wxTextEntry * const control = GetTextEntry(); wxTextEntry * const control = GetTextEntry();
@ -306,28 +306,28 @@ bool wxIntegerValidatorBase::DoValidateNumber(wxString * errMsg) const
return res; return res;
} }
// ============================================================================ // ============================================================================
// wxFloatingPointValidatorBase implementation // wxFloatingPointValidatorBase implementation
// ============================================================================ // ============================================================================
wxString wxFloatingPointValidatorBase::ToString(LongestValueType value) const wxString wxFloatingPointValidatorBase::ToString(LongestValueType value) const
{ {
return wxNumberFormatter::ToString(value, m_precision, GetFormatFlags()); return wxNumberFormatter::ToString(value, m_precision, GetFormatFlags());
} }
bool bool
wxFloatingPointValidatorBase::FromString(const wxString& s, wxFloatingPointValidatorBase::FromString(const wxString& s,
LongestValueType *value) LongestValueType *value)
{ {
return wxNumberFormatter::FromString(s, value); return wxNumberFormatter::FromString(s, value);
} }
bool bool
wxFloatingPointValidatorBase::IsCharOk(const wxString& val, wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
int pos, int pos,
wxChar ch) const wxChar ch) const
{ {
if ( ch == '-' ) if ( ch == '-' )
{ {
// We may accept minus sign if we can represent negative numbers at all. // We may accept minus sign if we can represent negative numbers at all.
if ( pos == 0 ) if ( pos == 0 )
@ -348,27 +348,27 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
return true; return true;
} }
const wxChar separator = wxNumberFormatter::GetDecimalSeparator(); const wxChar separator = wxNumberFormatter::GetDecimalSeparator();
if ( ch == separator ) if ( ch == separator )
{ {
if ( val.find(separator) != wxString::npos ) if ( val.find(separator) != wxString::npos )
{ {
// There is already a decimal separator, can't insert another one. // There is already a decimal separator, can't insert another one.
return false; return false;
} }
// Prepending a separator before the sign isn't allowed. // Prepending a separator before the sign isn't allowed.
if ( pos == 0 && !val.empty() && ( val[0] == '-' || val[0] == '+' ) ) if ( pos == 0 && !val.empty() && ( val[0] == '-' || val[0] == '+' ) )
return false; return false;
// Otherwise always accept it, adding a decimal separator doesn't // Otherwise always accept it, adding a decimal separator doesn't
// change the number value and, in particular, can't make it invalid. // change the number value and, in particular, can't make it invalid.
// OTOH the checks below might not pass because strings like "." or // OTOH the checks below might not pass because strings like "." or
// "-." are not valid numbers so parsing them would fail, hence we need // "-." are not valid numbers so parsing them would fail, hence we need
// to treat it specially here. // to treat it specially here.
return true; return true;
} }
// Must be a digit, an exponent or a thousands separator. // Must be a digit, an exponent or a thousands separator.
if( ( ch < '0' || ch > '9' ) && ch != 'E' && ch != 'e' ) if( ( ch < '0' || ch > '9' ) && ch != 'E' && ch != 'e' )
{ {
@ -389,7 +389,7 @@ wxFloatingPointValidatorBase::IsCharOk(const wxString& val,
str.insert(pos, ch); str.insert(pos, ch);
return ValidatePrecision(str); return ValidatePrecision(str);
} }
bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
{ {
wxTextEntry * const control = GetTextEntry(); wxTextEntry * const control = GetTextEntry();
@ -420,7 +420,7 @@ bool wxFloatingPointValidatorBase::DoValidateNumber(wxString * errMsg) const
{ {
res = ValidatePrecision(s); res = ValidatePrecision(s);
if ( !res ) if ( !res )
*errMsg = _("Too meany decimal digits"); *errMsg = _("Too many decimal digits");
else else
{ {
res = IsInRange(value); res = IsInRange(value);
@ -447,5 +447,5 @@ bool wxFloatingPointValidatorBase::ValidatePrecision(const wxString& s) const
// Return true if number has no more decimal digits than allowed // Return true if number has no more decimal digits than allowed
return ( (int)(posExp - posSep) - 1 <= (int)m_precision ); return ( (int)(posExp - posSep) - 1 <= (int)m_precision );
} }
#endif // wxUSE_VALIDATORS && wxUSE_TEXTCTRL #endif // wxUSE_VALIDATORS && wxUSE_TEXTCTRL