sync master with lastest vba changes
[ooovba.git] / sc / source / ui / cctrl / editfield.cxx
blob907a7ff84aa2fc9f39f70eabbff17f81f62bfef1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editfield.cxx,v $
10 * $Revision: 1.6.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #ifdef SC_DLLIMPLEMENTATION
35 #undef SC_DLLIMPLEMENTATION
36 #endif
37 #include "editfield.hxx"
38 #include <rtl/math.hxx>
39 #include <unotools/localedatawrapper.hxx>
40 #include "global.hxx"
42 // ============================================================================
44 namespace {
46 sal_Unicode lclGetDecSep()
48 return ScGlobal::GetpLocaleData()->getNumDecimalSep().GetChar( 0 );
51 sal_Unicode lclGetGroupSep()
53 return ScGlobal::GetpLocaleData()->getNumThousandSep().GetChar( 0 );
56 } // namespace
58 // ============================================================================
60 ScDoubleField::ScDoubleField( Window* pParent, const ResId& rResId ) :
61 Edit( pParent, rResId )
65 bool ScDoubleField::GetValue( double& rfValue ) const
67 String aStr( GetText() );
68 aStr.EraseLeadingAndTrailingChars( ' ' );
69 bool bOk = aStr.Len() > 0;
70 if( bOk )
72 rtl_math_ConversionStatus eStatus;
73 sal_Int32 nEnd;
74 rfValue = rtl::math::stringToDouble( aStr, lclGetDecSep(), lclGetGroupSep(), &eStatus, &nEnd );
75 bOk = (eStatus == rtl_math_ConversionStatus_Ok) && (nEnd == static_cast< sal_Int32 >( aStr.Len() ));
77 return bOk;
80 void ScDoubleField::SetValue( double fValue, sal_Int32 nDecPlaces, bool bEraseTrailingDecZeros )
82 SetText( ::rtl::math::doubleToUString( fValue, rtl_math_StringFormat_G,
83 nDecPlaces, lclGetDecSep(), bEraseTrailingDecZeros ) );
86 // ============================================================================