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 "XMLErrorIndicatorPropertyHdl.hxx"
27 #include <xmloff/xmluconv.hxx>
28 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
29 #include <rtl/ustrbuf.hxx>
30 
31 using namespace com::sun::star;
32 
~XMLErrorIndicatorPropertyHdl()33 XMLErrorIndicatorPropertyHdl::~XMLErrorIndicatorPropertyHdl()
34 {}
35 
importXML(const::rtl::OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const36 sal_Bool XMLErrorIndicatorPropertyHdl::importXML( const ::rtl::OUString& rStrImpValue,
37 												  uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
38 {
39 	sal_Bool bValue;
40 	SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
41 
42 	// modify existing value
43 	chart::ChartErrorIndicatorType eType = chart::ChartErrorIndicatorType_NONE;
44 	if( rValue.hasValue())
45 		rValue >>= eType;
46 
47 	if( bValue )	// enable flag
48 	{
49 		if( eType != chart::ChartErrorIndicatorType_TOP_AND_BOTTOM )
50 		{
51 			if( mbUpperIndicator )
52 				eType = ( eType == chart::ChartErrorIndicatorType_LOWER )
53 					? chart::ChartErrorIndicatorType_TOP_AND_BOTTOM
54 					: chart::ChartErrorIndicatorType_UPPER;
55 			else
56 				eType = ( eType == chart::ChartErrorIndicatorType_UPPER )
57 					? chart::ChartErrorIndicatorType_TOP_AND_BOTTOM
58 					: chart::ChartErrorIndicatorType_LOWER;
59 		}
60 	}
61 	else			// disable flag
62 	{
63 		if( eType != chart::ChartErrorIndicatorType_NONE )
64 		{
65 			if( mbUpperIndicator )
66 				eType = ( eType == chart::ChartErrorIndicatorType_UPPER )
67 					? chart::ChartErrorIndicatorType_NONE
68 					: chart::ChartErrorIndicatorType_LOWER;
69 			else
70 				eType = ( eType == chart::ChartErrorIndicatorType_LOWER )
71 					? chart::ChartErrorIndicatorType_NONE
72 					: chart::ChartErrorIndicatorType_UPPER;
73 		}
74 	}
75 
76 	rValue <<= eType;
77 
78 	return sal_True;
79 }
80 
exportXML(::rtl::OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const81 sal_Bool XMLErrorIndicatorPropertyHdl::exportXML( ::rtl::OUString& rStrExpValue,
82 												  const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
83 {
84 	rtl::OUStringBuffer aBuffer;
85 	chart::ChartErrorIndicatorType eType;
86 
87 	rValue >>= eType;
88 	sal_Bool bValue = ( eType == chart::ChartErrorIndicatorType_TOP_AND_BOTTOM ||
89 						( mbUpperIndicator
90 						  ? ( eType == chart::ChartErrorIndicatorType_UPPER )
91 						  : ( eType == chart::ChartErrorIndicatorType_LOWER )));
92 
93 	if( bValue )
94 	{
95 		SvXMLUnitConverter::convertBool( aBuffer, bValue );
96 		rStrExpValue = aBuffer.makeStringAndClear();
97 	}
98 
99 	// only export if set to true
100 	return bValue;
101 }
102