1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include "XMLErrorIndicatorPropertyHdl.hxx"
31 #include <xmloff/xmluconv.hxx>
32 #include <com/sun/star/chart/ChartErrorIndicatorType.hpp>
33 #include <rtl/ustrbuf.hxx>
34 
35 using namespace com::sun::star;
36 
37 XMLErrorIndicatorPropertyHdl::~XMLErrorIndicatorPropertyHdl()
38 {}
39 
40 sal_Bool XMLErrorIndicatorPropertyHdl::importXML( const ::rtl::OUString& rStrImpValue,
41 												  uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
42 {
43 	sal_Bool bValue;
44 	SvXMLUnitConverter::convertBool( bValue, rStrImpValue );
45 
46 	// modify existing value
47 	chart::ChartErrorIndicatorType eType = chart::ChartErrorIndicatorType_NONE;
48 	if( rValue.hasValue())
49 		rValue >>= eType;
50 
51 	if( bValue )	// enable flag
52 	{
53 		if( eType != chart::ChartErrorIndicatorType_TOP_AND_BOTTOM )
54 		{
55 			if( mbUpperIndicator )
56 				eType = ( eType == chart::ChartErrorIndicatorType_LOWER )
57 					? chart::ChartErrorIndicatorType_TOP_AND_BOTTOM
58 					: chart::ChartErrorIndicatorType_UPPER;
59 			else
60 				eType = ( eType == chart::ChartErrorIndicatorType_UPPER )
61 					? chart::ChartErrorIndicatorType_TOP_AND_BOTTOM
62 					: chart::ChartErrorIndicatorType_LOWER;
63 		}
64 	}
65 	else			// disable flag
66 	{
67 		if( eType != chart::ChartErrorIndicatorType_NONE )
68 		{
69 			if( mbUpperIndicator )
70 				eType = ( eType == chart::ChartErrorIndicatorType_UPPER )
71 					? chart::ChartErrorIndicatorType_NONE
72 					: chart::ChartErrorIndicatorType_LOWER;
73 			else
74 				eType = ( eType == chart::ChartErrorIndicatorType_LOWER )
75 					? chart::ChartErrorIndicatorType_NONE
76 					: chart::ChartErrorIndicatorType_UPPER;
77 		}
78 	}
79 
80 	rValue <<= eType;
81 
82 	return sal_True;
83 }
84 
85 sal_Bool XMLErrorIndicatorPropertyHdl::exportXML( ::rtl::OUString& rStrExpValue,
86 												  const uno::Any& rValue, const SvXMLUnitConverter& /*rUnitConverter*/ ) const
87 {
88 	rtl::OUStringBuffer aBuffer;
89 	chart::ChartErrorIndicatorType eType;
90 
91 	rValue >>= eType;
92 	sal_Bool bValue = ( eType == chart::ChartErrorIndicatorType_TOP_AND_BOTTOM ||
93 						( mbUpperIndicator
94 						  ? ( eType == chart::ChartErrorIndicatorType_UPPER )
95 						  : ( eType == chart::ChartErrorIndicatorType_LOWER )));
96 
97 	if( bValue )
98 	{
99 		SvXMLUnitConverter::convertBool( aBuffer, bValue );
100 		rStrExpValue = aBuffer.makeStringAndClear();
101 	}
102 
103 	// only export if set to true
104 	return bValue;
105 }
106