1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-01-16 09:31:14 +01:00

Remove some macro _ in NumericTextCtrl & substitute-don't-concatenate

This commit is contained in:
Paul Licameli
2020-05-06 08:40:26 -04:00
parent 630bc15fd3
commit a0045f8772
2 changed files with 82 additions and 47 deletions

View File

@@ -285,7 +285,7 @@ private:
struct BuiltinFormatString struct BuiltinFormatString
{ {
NumericFormatSymbol name; NumericFormatSymbol name;
TranslatableString formatStr; NumericConverter::FormatStrings formatStrings;
friend inline bool operator == friend inline bool operator ==
(const BuiltinFormatString &a, const BuiltinFormatString &b) (const BuiltinFormatString &a, const BuiltinFormatString &b)
@@ -561,16 +561,23 @@ static const BuiltinFormatString FrequencyConverterFormats_[] = {
{ {
/* i18n-hint: Name of display format that shows frequency in hertz */ /* i18n-hint: Name of display format that shows frequency in hertz */
{ XO("Hz") }, { XO("Hz") },
/* i18n-hint: Format string for displaying frequency in hertz. Change {
/* i18n-hint: Format string for displaying frequency in hertz. Change
* the decimal point for your locale. Don't change the numbers. */ * the decimal point for your locale. Don't change the numbers. */
XO("0100000.0100 Hz") XO("0100000.0100 Hz")
, XO("centihertz")
}
}, },
{ {
/* i18n-hint: Name of display format that shows frequency in kilohertz */
{ XO("kHz") }, { XO("kHz") },
/* i18n-hint: Format string for displaying frequency in kilohertz. Change {
/* i18n-hint: Format string for displaying frequency in kilohertz. Change
* the decimal point for your locale. Don't change the numbers. */ * the decimal point for your locale. Don't change the numbers. */
XO("01000.01000 kHz|0.001") XO("01000.01000 kHz|0.001")
, XO("hertz")
}
}, },
}; };
@@ -583,28 +590,40 @@ static const BuiltinFormatString BandwidthConverterFormats_[] = {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in octaves */ * in octaves */
{ XO("octaves") }, { XO("octaves") },
{
/* i18n-hint: Format string for displaying log of frequency in octaves. /* i18n-hint: Format string for displaying log of frequency in octaves.
* Change the decimal points for your locale. Don't change the numbers. */ * Change the decimal points for your locale. Don't change the numbers. */
XO("100.01000 octaves|1.442695041"), // Scale factor is 1 / ln (2) XO("100.01000 octaves|1.442695041"), // Scale factor is 1 / ln (2)
/* i18n-hint: an octave is a doubling of frequency */
XO("thousandths of octaves")
}
}, },
{ {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in semitones and cents */ * in semitones and cents */
{ XO("semitones + cents") }, { XO("semitones + cents") },
/* i18n-hint: Format string for displaying log of frequency in semitones {
* and cents. /* i18n-hint: Format string for displaying log of frequency in semitones
* Change the decimal points for your locale. Don't change the numbers. */ * and cents.
XO("1000 semitones .0100 cents|17.312340491"), // Scale factor is 12 / ln (2) * Change the decimal points for your locale. Don't change the numbers. */
XO("1000 semitones .0100 cents|17.312340491"), // Scale factor is 12 / ln (2)
/* i18n-hint: a cent is a hundredth of a semitone (which is 1/12 octave) */
XO("hundredths of cents")
}
}, },
{ {
/* i18n-hint: Name of display format that shows log of frequency /* i18n-hint: Name of display format that shows log of frequency
* in decades */ * in decades */
{ XO("decades") }, { XO("decades") },
/* i18n-hint: Format string for displaying log of frequency in decades. {
* Change the decimal points for your locale. Don't change the numbers. */ /* i18n-hint: Format string for displaying log of frequency in decades.
XO("10.01000 decades|0.434294482"), // Scale factor is 1 / ln (10) * Change the decimal points for your locale. Don't change the numbers. */
XO("10.01000 decades|0.434294482"), // Scale factor is 1 / ln (10)
/* i18n-hint: a decade is a tenfold increase of frequency */
XO("thousandths of decades")
}
}, },
}; };
@@ -1126,11 +1145,11 @@ bool NumericConverter::SetFormatName(const NumericFormatSymbol & formatName)
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
bool NumericConverter::SetFormatString(const TranslatableString & formatString) bool NumericConverter::SetFormatString(const FormatStrings & formatString)
{ {
if (mFormatString != formatString) { if (mFormatString != formatString) {
mFormatString = formatString; mFormatString = formatString;
ParseFormatString(mFormatString); ParseFormatString(mFormatString.formatStr);
ValueToControls(); ValueToControls();
ControlsToValue(); ControlsToValue();
return true; return true;
@@ -1142,7 +1161,7 @@ bool NumericConverter::SetFormatString(const TranslatableString & formatString)
void NumericConverter::SetSampleRate(double sampleRate) void NumericConverter::SetSampleRate(double sampleRate)
{ {
mSampleRate = sampleRate; mSampleRate = sampleRate;
ParseFormatString(mFormatString); ParseFormatString(mFormatString.formatStr);
ValueToControls(); ValueToControls();
ControlsToValue(); ControlsToValue();
} }
@@ -1218,16 +1237,16 @@ NumericFormatSymbol NumericConverter::GetBuiltinName(const int index)
return {}; return {};
} }
TranslatableString NumericConverter::GetBuiltinFormat(const int index) auto NumericConverter::GetBuiltinFormat(const int index) -> FormatStrings
{ {
if (index >= 0 && index < GetNumBuiltins()) if (index >= 0 && index < GetNumBuiltins())
return mBuiltinFormatStrings[index].formatStr; return mBuiltinFormatStrings[index].formatStrings;
return {}; return {};
} }
TranslatableString NumericConverter::GetBuiltinFormat( auto NumericConverter::GetBuiltinFormat(
const NumericFormatSymbol &name) const NumericFormatSymbol &name) -> FormatStrings
{ {
int ndx = int ndx =
std::find( mBuiltinFormatStrings, mBuiltinFormatStrings + mNBuiltins, std::find( mBuiltinFormatStrings, mBuiltinFormatStrings + mNBuiltins,
@@ -1419,7 +1438,7 @@ NumericTextCtrl::NumericTextCtrl(wxWindow *parent, wxWindowID id,
if (options.hasInvalidValue) if (options.hasInvalidValue)
SetInvalidValue( options.invalidValue ); SetInvalidValue( options.invalidValue );
if (!options.format.empty()) if (!options.format.formatStr.empty())
SetFormatString( options.format ); SetFormatString( options.format );
if (options.hasValue) if (options.hasValue)
@@ -1460,7 +1479,7 @@ bool NumericTextCtrl::SetFormatName(const NumericFormatSymbol & formatName)
SetFormatString(GetBuiltinFormat(formatName)); SetFormatString(GetBuiltinFormat(formatName));
} }
bool NumericTextCtrl::SetFormatString(const TranslatableString & formatString) bool NumericTextCtrl::SetFormatString(const FormatStrings & formatString)
{ {
auto result = auto result =
NumericConverter::SetFormatString(formatString); NumericConverter::SetFormatString(formatString);
@@ -2255,6 +2274,22 @@ wxAccStatus NumericTextCtrlAx::GetLocation(wxRect & rect, int elementId)
return wxACC_OK; return wxACC_OK;
} }
static void GetFraction( wxString &label,
const NumericConverter::FormatStrings &formatStrings,
bool isTime, int digits )
{
TranslatableString tr = formatStrings.fraction;
if ( tr.empty() ) {
wxASSERT( isTime );
if (digits == 2)
tr = XO("centiseconds");
else if (digits == 3)
tr = XO("milliseconds");
}
if (!tr.empty())
label = tr.Translation();
}
// Gets the name of the specified object. // Gets the name of the specified object.
wxAccStatus NumericTextCtrlAx::GetName(int childId, wxString *name) wxAccStatus NumericTextCtrlAx::GetName(int childId, wxString *name)
{ {
@@ -2306,26 +2341,8 @@ wxAccStatus NumericTextCtrlAx::GetName(int childId, wxString *name)
if (field > 1 && field == cnt) { if (field > 1 && field == cnt) {
if (mFields[field - 2].label == decimal) { if (mFields[field - 2].label == decimal) {
int digits = mFields[field - 1].digits; int digits = mFields[field - 1].digits;
if (digits == 2) { GetFraction( label, mCtrl->mFormatString,
if (isTime) isTime, digits );
label = _("centiseconds");
else {
// other units
// PRL: does this create translation problems?
label = _("hundredths of ");
label += mFields[field - 1].label;
}
}
else if (digits == 3) {
if (isTime)
label = _("milliseconds");
else {
// other units
// PRL: does this create translation problems?
label = _("thousandths of ");
label += mFields[field - 1].label;
}
}
} }
} }
// If the field following this one represents fractions of a // If the field following this one represents fractions of a

View File

@@ -54,6 +54,24 @@ public:
BANDWIDTH, BANDWIDTH,
}; };
struct FormatStrings {
TranslatableString formatStr;
// How to name the fraction of the unit; not necessary for time formats
// or when the format string has no decimal point
TranslatableString fraction;
FormatStrings(
const TranslatableString &format = {},
const TranslatableString &fraction = {})
: formatStr{ format }, fraction{ fraction }
{}
friend bool operator == ( const FormatStrings &x, const FormatStrings &y )
{ return x.formatStr == y.formatStr && x.fraction == y.fraction; }
friend bool operator != ( const FormatStrings &x, const FormatStrings &y )
{ return !(x == y); }
};
static NumericFormatSymbol DefaultSelectionFormat(); static NumericFormatSymbol DefaultSelectionFormat();
static NumericFormatSymbol TimeAndSampleFormat(); static NumericFormatSymbol TimeAndSampleFormat();
static NumericFormatSymbol SecondsFormat(); static NumericFormatSymbol SecondsFormat();
@@ -90,7 +108,7 @@ public:
bool SetFormatName(const NumericFormatSymbol & formatName); bool SetFormatName(const NumericFormatSymbol & formatName);
// returns true iff the format string really changed: // returns true iff the format string really changed:
bool SetFormatString(const TranslatableString & formatString); bool SetFormatString(const FormatStrings & formatString);
void SetSampleRate(double sampleRate); void SetSampleRate(double sampleRate);
void SetValue(double newValue); void SetValue(double newValue);
@@ -107,8 +125,8 @@ public:
int GetNumBuiltins(); int GetNumBuiltins();
NumericFormatSymbol GetBuiltinName(const int index); NumericFormatSymbol GetBuiltinName(const int index);
TranslatableString GetBuiltinFormat(const int index); FormatStrings GetBuiltinFormat(const int index);
TranslatableString GetBuiltinFormat(const NumericFormatSymbol & name); FormatStrings GetBuiltinFormat(const NumericFormatSymbol & name);
// Adjust the value by the number "steps" in the active format. // Adjust the value by the number "steps" in the active format.
// Increment if "dir" is 1, decrement if "dir" is -1. // Increment if "dir" is 1, decrement if "dir" is -1.
@@ -126,7 +144,7 @@ protected:
double mMaxValue; double mMaxValue;
double mInvalidValue; double mInvalidValue;
TranslatableString mFormatString; FormatStrings mFormatString;
std::vector<NumericField> mFields; std::vector<NumericField> mFields;
wxString mPrefix; wxString mPrefix;
@@ -160,7 +178,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
bool menuEnabled { true }; bool menuEnabled { true };
bool hasInvalidValue { false }; bool hasInvalidValue { false };
double invalidValue { -1.0 }; double invalidValue { -1.0 };
TranslatableString format {}; FormatStrings format {};
bool hasValue { false }; bool hasValue { false };
double value{ -1.0 }; double value{ -1.0 };
@@ -172,7 +190,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
Options &InvalidValue (bool has, double v = -1.0) Options &InvalidValue (bool has, double v = -1.0)
{ hasInvalidValue = has, invalidValue = v; return *this; } { hasInvalidValue = has, invalidValue = v; return *this; }
// use a custom format not in the tables: // use a custom format not in the tables:
Options &Format (const TranslatableString &f) Options &Format (const FormatStrings &f)
{ format = f; return *this; } { format = f; return *this; }
Options &Value (bool has, double v) Options &Value (bool has, double v)
{ hasValue = has, value = v; return *this; } { hasValue = has, value = v; return *this; }
@@ -200,7 +218,7 @@ class NumericTextCtrl final : public wxControl, public NumericConverter
void SetValue(double newValue); void SetValue(double newValue);
// returns true iff the format string really changed: // returns true iff the format string really changed:
bool SetFormatString(const TranslatableString & formatString); bool SetFormatString(const FormatStrings & formatString);
// returns true iff the format name really changed: // returns true iff the format name really changed:
bool SetFormatName(const NumericFormatSymbol & formatName); bool SetFormatName(const NumericFormatSymbol & formatName);