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_xmloff.hxx"
26 #include "XMLAxisPositionPropertyHdl.hxx"
27 #include <xmloff/xmluconv.hxx>
28 #include <com/sun/star/chart/ChartAxisPosition.hpp>
29 #include <rtl/ustrbuf.hxx>
30
31 using namespace ::xmloff::token;
32 using ::rtl::OUString;
33 using ::rtl::OUStringBuffer;
34
35 using namespace com::sun::star;
36
XMLAxisPositionPropertyHdl(bool bCrossingValue)37 XMLAxisPositionPropertyHdl::XMLAxisPositionPropertyHdl( bool bCrossingValue )
38 : m_bCrossingValue( bCrossingValue )
39 {}
40
~XMLAxisPositionPropertyHdl()41 XMLAxisPositionPropertyHdl::~XMLAxisPositionPropertyHdl()
42 {}
43
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const44 sal_Bool XMLAxisPositionPropertyHdl::importXML( const OUString& rStrImpValue,
45 uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
46 {
47 sal_Bool bResult = false;
48
49 if( rStrImpValue.equals( GetXMLToken(XML_START) ) )
50 {
51 if( !m_bCrossingValue )
52 {
53 rValue <<= ::com::sun::star::chart::ChartAxisPosition_START;
54 bResult = true;
55 }
56 }
57 else if( rStrImpValue.equals( GetXMLToken(XML_END) ) )
58 {
59 if( !m_bCrossingValue )
60 {
61 rValue <<= ::com::sun::star::chart::ChartAxisPosition_END;
62 bResult = true;
63 }
64 }
65 else
66 {
67 if( !m_bCrossingValue )
68 {
69 rValue <<= ::com::sun::star::chart::ChartAxisPosition_VALUE;
70 bResult = true;
71 }
72 else
73 {
74 double fDblValue=0.0;
75 bResult = SvXMLUnitConverter::convertDouble( fDblValue, rStrImpValue );
76 rValue <<= fDblValue;
77 }
78 }
79
80 return bResult;
81 }
82
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const83 sal_Bool XMLAxisPositionPropertyHdl::exportXML( OUString& rStrExpValue,
84 const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
85 {
86 sal_Bool bResult = sal_False;
87
88 rtl::OUStringBuffer sValueBuffer;
89 if( m_bCrossingValue )
90 {
91 if(rStrExpValue.getLength() == 0)
92 {
93 double fValue = 0.0;
94 rValue >>= fValue;
95 SvXMLUnitConverter::convertDouble( sValueBuffer, fValue );
96 rStrExpValue = sValueBuffer.makeStringAndClear();
97 bResult = true;
98 }
99 }
100 else
101 {
102 ::com::sun::star::chart::ChartAxisPosition ePosition( ::com::sun::star::chart::ChartAxisPosition_ZERO );
103 rValue >>= ePosition;
104 switch(ePosition)
105 {
106 case ::com::sun::star::chart::ChartAxisPosition_START:
107 rStrExpValue = GetXMLToken( XML_START );
108 bResult = true;
109 break;
110 case ::com::sun::star::chart::ChartAxisPosition_END:
111 rStrExpValue = GetXMLToken( XML_END );
112 bResult = true;
113 break;
114 case ::com::sun::star::chart::ChartAxisPosition_ZERO:
115 SvXMLUnitConverter::convertDouble( sValueBuffer, 0.0 );
116 rStrExpValue = sValueBuffer.makeStringAndClear();
117 bResult = true;
118 break;
119 default:
120 break;
121 }
122 }
123 return bResult;
124 }
125