xref: /aoo42x/main/sc/source/ui/cctrl/editfield.cxx (revision a479921a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scui.hxx"
26 
27 #include "editfield.hxx"
28 #include <rtl/math.hxx>
29 #include <unotools/localedatawrapper.hxx>
30 #include "global.hxx"
31 
32 // ============================================================================
33 
34 namespace {
35 
lclGetDecSep()36 sal_Unicode lclGetDecSep()
37 {
38     return ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar( 0 );
39 }
40 
lclGetGroupSep()41 sal_Unicode lclGetGroupSep()
42 {
43     return ScGlobal::GetpLocaleData()->getNumThousandSep().GetChar( 0 );
44 }
45 
46 } // namespace
47 
48 // ============================================================================
49 
ScDoubleField(Window * pParent,const ResId & rResId)50 ScDoubleField::ScDoubleField( Window* pParent, const ResId& rResId ) :
51     Edit( pParent, rResId )
52 {
53 }
54 
GetValue(double & rfValue) const55 bool ScDoubleField::GetValue( double& rfValue ) const
56 {
57     String aStr( GetText() );
58     aStr.EraseLeadingAndTrailingChars( ' ' );
59     bool bOk = aStr.Len() > 0;
60     if( bOk )
61     {
62         rtl_math_ConversionStatus eStatus;
63         sal_Int32 nEnd;
64         rfValue = rtl::math::stringToDouble( aStr, lclGetDecSep(), lclGetGroupSep(), &eStatus, &nEnd );
65         bOk = (eStatus == rtl_math_ConversionStatus_Ok) && (nEnd == static_cast< sal_Int32 >( aStr.Len() ));
66     }
67     return bOk;
68 }
69 
SetValue(double fValue,sal_Int32 nDecPlaces,bool bEraseTrailingDecZeros)70 void ScDoubleField::SetValue( double fValue, sal_Int32 nDecPlaces, bool bEraseTrailingDecZeros )
71 {
72     SetText( ::rtl::math::doubleToUString( fValue, rtl_math_StringFormat_G,
73         nDecPlaces, lclGetDecSep(), bEraseTrailingDecZeros ) );
74 }
75 
76 // ============================================================================
77 
78