LibreOffice Module sc (master) 1
editfield.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#ifdef SC_DLLIMPLEMENTATION
21#undef SC_DLLIMPLEMENTATION
22#endif
23#include <editfield.hxx>
24#include <comphelper/string.hxx>
25#include <rtl/math.hxx>
27#include <global.hxx>
28
29namespace {
30
31sal_Unicode lclGetDecSep()
32{
34}
35
36} // namespace
37
38ScDoubleField::ScDoubleField(std::unique_ptr<weld::Entry> xEntry)
39 : m_xEntry(std::move(xEntry))
40{
41}
42
43bool ScDoubleField::GetValue( double& rfValue ) const
44{
45 OUString aStr(comphelper::string::strip(m_xEntry->get_text(), ' '));
46 bool bOk = !aStr.isEmpty();
47 if( bOk )
48 {
49 rtl_math_ConversionStatus eStatus;
50 sal_Int32 nEnd;
51 rfValue = ScGlobal::getLocaleData().stringToDouble( aStr, true, &eStatus, &nEnd );
52 bOk = (eStatus == rtl_math_ConversionStatus_Ok) && (nEnd == aStr.getLength() );
53 }
54 return bOk;
55}
56
57void ScDoubleField::SetValue( double fValue, sal_Int32 nDecPlaces )
58{
59 m_xEntry->set_text( ::rtl::math::doubleToUString( fValue, rtl_math_StringFormat_G,
60 nDecPlaces, lclGetDecSep(), true/*bEraseTrailingDecZeros*/ ) );
61}
62
63/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
double stringToDouble(std::u16string_view aString, bool bUseGroupSep, rtl_math_ConversionStatus *pStatus, sal_Int32 *pParseEnd) const
const OUString & getNumDecimalSep() const
void SetValue(double fValue, sal_Int32 nDecPlaces=12)
Definition: editfield.cxx:57
ScDoubleField(std::unique_ptr< weld::Entry > xEntry)
Definition: editfield.cxx:38
std::unique_ptr< weld::Entry > m_xEntry
Definition: editfield.hxx:28
bool GetValue(double &rfValue) const
Definition: editfield.cxx:43
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1016
aStr
OString strip(const OString &rIn, char c)
sal_uInt16 sal_Unicode