summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-02-14 10:51:39 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-02-14 15:36:23 +0100
commit17231d0b94ef47f602db2a40875e7274d938b15b (patch)
tree3ab42d16d6775ecb77d82ab29ce27b31532ae54c
parent54acab919e7c7c5d60fc697bda54278861ac250e (diff)
split StringToMetric and TextToValue into fieldvalue.hxx
Change-Id: I5d1102f7a50a7a246df9f6de8b7a6df6557eb54d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88682 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--include/vcl/field.hxx3
-rw-r--r--include/vcl/fieldvalues.hxx8
-rw-r--r--sd/source/ui/dlg/diactrl.cxx4
-rw-r--r--svtools/source/control/ctrlbox.cxx2
-rw-r--r--svx/source/dialog/svxruler.cxx6
-rw-r--r--vcl/source/control/field.cxx52
-rw-r--r--vcl/source/window/builder.cxx2
7 files changed, 44 insertions, 33 deletions
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx
index c011132f4c81..7cb371a25e4a 100644
--- a/include/vcl/field.hxx
+++ b/include/vcl/field.hxx
@@ -219,9 +219,6 @@ public:
virtual OUString CreateFieldText( sal_Int64 nValue ) const override;
sal_Int64 GetCorrectedValue( FieldUnit eOutUnit ) const;
- static FieldUnit StringToMetric(const OUString &rMetricString);
- static bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit);
-
protected:
FieldUnit meUnit;
diff --git a/include/vcl/fieldvalues.hxx b/include/vcl/fieldvalues.hxx
index e36b0590ae71..e8f78bd5e119 100644
--- a/include/vcl/fieldvalues.hxx
+++ b/include/vcl/fieldvalues.hxx
@@ -21,11 +21,19 @@
#define INCLUDED_VCL_FIELDVALUES_HXX
#include <vcl/dllapi.h>
+#include <rtl/ustring.hxx>
#include <tools/fldunit.hxx>
#include <tools/mapunit.hxx>
+class LocaleDataWrapper;
+
namespace vcl
{
+VCL_DLLPUBLIC FieldUnit StringToMetric(const OUString& rMetricString);
+VCL_DLLPUBLIC bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
+ sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper,
+ FieldUnit eUnit);
+
VCL_DLLPUBLIC sal_Int64 ConvertValue(sal_Int64 nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits,
FieldUnit eInUnit, FieldUnit eOutUnit);
VCL_DLLPUBLIC sal_Int64 ConvertValue(sal_Int64 nValue, sal_uInt16 nDecDigits, MapUnit eInUnit,
diff --git a/sd/source/ui/dlg/diactrl.cxx b/sd/source/ui/dlg/diactrl.cxx
index 20abb42b9bb3..ffe04874eef0 100644
--- a/sd/source/ui/dlg/diactrl.cxx
+++ b/sd/source/ui/dlg/diactrl.cxx
@@ -17,7 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <vcl/field.hxx>
+#include <vcl/fieldvalues.hxx>
#include <svl/intitem.hxx>
#include <vcl/toolbox.hxx>
@@ -116,7 +116,7 @@ IMPL_LINK(SdPagesField, spin_button_input, int*, result, bool)
{
const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
double fResult(0.0);
- bool bRet = MetricFormatter::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
+ bool bRet = vcl::TextToValue(m_xWidget->get_text(), fResult, 0, m_xWidget->get_digits(), rLocaleData, FieldUnit::NONE);
if (bRet)
{
if (fResult > SAL_MAX_INT32)
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index cbb8f349f0d7..04b586a82253 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -1180,7 +1180,7 @@ int FontSizeBox::get_value() const
const SvtSysLocale aSysLocale;
const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
double fResult(0.0);
- (void)MetricFormatter::TextToValue(aStr, fResult, 0, GetDecimalDigits(), rLocaleData, GetUnit());
+ (void)vcl::TextToValue(aStr, fResult, 0, GetDecimalDigits(), rLocaleData, GetUnit());
if (!aStr.isEmpty())
{
if (fResult < nMin)
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 84792e8058c6..3a0e28473148 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -23,7 +23,7 @@
#include <vcl/builder.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
-#include <vcl/field.hxx>
+#include <vcl/fieldvalues.hxx>
#include <vcl/image.hxx>
#include <vcl/settings.hxx>
#include <vcl/virdev.hxx>
@@ -3253,7 +3253,7 @@ void SvxRuler::Notify(SfxBroadcaster&, const SfxHint& rHint)
IMPL_LINK( SvxRuler, MenuSelect, Menu *, pMenu, bool )
{
/* Handler of the context menus for switching the unit of measurement */
- SetUnit(MetricFormatter::StringToMetric(OUString::fromUtf8(pMenu->GetCurItemIdent())));
+ SetUnit(vcl::StringToMetric(OUString::fromUtf8(pMenu->GetCurItemIdent())));
return false;
}
@@ -3332,7 +3332,7 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent )
{
sal_uInt16 nId = aMenu->GetItemId(i - 1);
OString sIdent = aMenu->GetItemIdent(nId);
- FieldUnit eMenuUnit = MetricFormatter::StringToMetric(OUString::fromUtf8(sIdent));
+ FieldUnit eMenuUnit = vcl::StringToMetric(OUString::fromUtf8(sIdent));
aMenu->CheckItem(nId, eMenuUnit == eUnit);
if( bReduceMetric )
{
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 4d7d08447323..0cc13221129e 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -1052,23 +1052,26 @@ static OUString ImplMetricToString( FieldUnit rUnit )
return OUString();
}
-FieldUnit MetricFormatter::StringToMetric(const OUString &rMetricString)
+namespace vcl
{
- // return FieldUnit
- OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
- for (auto const& elem : ImplGetCleanedFieldUnits())
+ FieldUnit StringToMetric(const OUString &rMetricString)
{
- if ( elem.first == aStr )
- return elem.second;
- }
+ // return FieldUnit
+ OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
+ for (auto const& elem : ImplGetCleanedFieldUnits())
+ {
+ if ( elem.first == aStr )
+ return elem.second;
+ }
- return FieldUnit::NONE;
+ return FieldUnit::NONE;
+ }
}
static FieldUnit ImplMetricGetUnit(const OUString& rStr)
{
OUString aStr = ImplMetricGetUnitText(rStr);
- return MetricFormatter::StringToMetric(aStr);
+ return vcl::StringToMetric(aStr);
}
#define K *1000L
@@ -1357,27 +1360,30 @@ namespace vcl
}
}
-bool MetricFormatter::TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
- sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit)
+namespace vcl
{
- // Get value
- sal_Int64 nValue;
- if ( !ImplNumericGetValue( rStr, nValue, nDecDigits, rLocaleDataWrapper ) )
- return false;
+ bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue,
+ sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit)
+ {
+ // Get value
+ sal_Int64 nValue;
+ if ( !ImplNumericGetValue( rStr, nValue, nDecDigits, rLocaleDataWrapper ) )
+ return false;
- // Determine unit
- FieldUnit eEntryUnit = ImplMetricGetUnit( rStr );
+ // Determine unit
+ FieldUnit eEntryUnit = ImplMetricGetUnit( rStr );
- // Recalculate unit
- // caution: conversion to double loses precision
- rValue = vcl::ConvertDoubleValue(static_cast<double>(nValue), nBaseValue, nDecDigits, eEntryUnit, eUnit);
+ // Recalculate unit
+ // caution: conversion to double loses precision
+ rValue = vcl::ConvertDoubleValue(static_cast<double>(nValue), nBaseValue, nDecDigits, eEntryUnit, eUnit);
- return true;
+ return true;
+ }
}
void MetricFormatter::ImplMetricReformat( const OUString& rStr, double& rValue, OUString& rOutStr )
{
- if ( !TextToValue( rStr, rValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) )
+ if (!vcl::TextToValue(rStr, rValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
return;
double nTempVal = rValue;
@@ -1476,7 +1482,7 @@ sal_Int64 MetricFormatter::GetValueFromStringUnit(const OUString& rStr, FieldUni
{
double nTempValue;
// caution: precision loss in double cast
- if (!TextToValue(rStr, nTempValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
+ if (!vcl::TextToValue(rStr, nTempValue, 0, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit))
nTempValue = static_cast<double>(mnLastValue);
// caution: precision loss in double cast
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 5987856e1e6b..da3e2e8e8e57 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -311,7 +311,7 @@ namespace weld
{
const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetLocaleDataWrapper();
double fResult(0.0);
- bool bRet = MetricFormatter::TextToValue(get_text(), fResult, 0, m_xSpinButton->get_digits(), rLocaleData, m_eSrcUnit);
+ bool bRet = vcl::TextToValue(get_text(), fResult, 0, m_xSpinButton->get_digits(), rLocaleData, m_eSrcUnit);
if (bRet)
{
if (fResult > SAL_MAX_INT32)