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_chart2.hxx"
26 
27 #include "ConfigurationAccess.hxx"
28 #include "macros.hxx"
29 
30 // header for class SvtSysLocale
31 #include <unotools/syslocale.hxx>
32 // header for class ConfigItem
33 #include <unotools/configitem.hxx>
34 // header for rtl::Static
35 #include <rtl/instance.hxx>
36 
37 
38 //.............................................................................
39 namespace chart
40 {
41 //.............................................................................
42 using namespace ::com::sun::star;
43 
44 namespace
45 {
lcl_IsMetric()46 bool lcl_IsMetric()
47 {
48     SvtSysLocale aSysLocale;
49     const LocaleDataWrapper* pLocWrapper = aSysLocale.GetLocaleDataPtr();
50     MeasurementSystem eSys = pLocWrapper->getMeasurementSystemEnum();
51 
52     return ( eSys == MEASURE_METRIC );
53 }
54 }//end anonymous namespace
55 
56 // ----------------------------------------
57 
58 class CalcConfigItem : public ::utl::ConfigItem
59 {
60 public:
61     CalcConfigItem();
62     virtual ~CalcConfigItem();
63 
64     FieldUnit getFieldUnit();
65     virtual void                    Commit();
66     virtual void                    Notify( const uno::Sequence<rtl::OUString>& aPropertyNames);
67 };
68 
CalcConfigItem()69 CalcConfigItem::CalcConfigItem()
70     : ConfigItem( ::rtl::OUString( C2U( "Office.Calc/Layout" )))
71 {
72 }
73 
~CalcConfigItem()74 CalcConfigItem::~CalcConfigItem()
75 {
76 }
77 
Commit()78 void CalcConfigItem::Commit() {}
Notify(const uno::Sequence<rtl::OUString> &)79 void CalcConfigItem::Notify( const uno::Sequence<rtl::OUString>& ) {}
80 
getFieldUnit()81 FieldUnit CalcConfigItem::getFieldUnit()
82 {
83     FieldUnit eResult( FUNIT_CM );
84 
85     uno::Sequence< ::rtl::OUString > aNames( 1 );
86     if( lcl_IsMetric() )
87         aNames[ 0 ] = ::rtl::OUString( C2U( "Other/MeasureUnit/Metric" ));
88     else
89         aNames[ 0 ] = ::rtl::OUString( C2U( "Other/MeasureUnit/NonMetric" ));
90 
91     uno::Sequence< uno::Any > aResult( GetProperties( aNames ));
92     sal_Int32 nValue = 0;
93     if( aResult[ 0 ] >>= nValue )
94         eResult = static_cast< FieldUnit >( nValue );
95 
96     return eResult;
97 }
98 
99 namespace
100 {
101     //a CalcConfigItem Singleton
102     struct theCalcConfigItem : public rtl::Static< CalcConfigItem, theCalcConfigItem > {};
103 }
104 
105 namespace ConfigurationAccess
106 {
getFieldUnit()107     FieldUnit getFieldUnit()
108     {
109         FieldUnit aUnit( theCalcConfigItem::get().getFieldUnit() );
110         return aUnit;
111     }
112 } //namespace ConfigurationAccess
113 
114 //.............................................................................
115 } //namespace chart
116 //.............................................................................
117