1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
28cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
29cdf0e10cSrcweir #include "XMLPercentOrMeasurePropertyHandler.hxx"
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir using namespace ::com::sun::star::uno;
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::rtl::OUStringBuffer;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
XMLPercentOrMeasurePropertyHandler(sal_Bool bPercent)38cdf0e10cSrcweir XMLPercentOrMeasurePropertyHandler::XMLPercentOrMeasurePropertyHandler( sal_Bool bPercent )
39cdf0e10cSrcweir : mbPercent( bPercent )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
~XMLPercentOrMeasurePropertyHandler()43cdf0e10cSrcweir XMLPercentOrMeasurePropertyHandler::~XMLPercentOrMeasurePropertyHandler()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter & rUnitConverter) const47cdf0e10cSrcweir sal_Bool XMLPercentOrMeasurePropertyHandler::importXML(
48cdf0e10cSrcweir 	const OUString& rStrImpValue,
49cdf0e10cSrcweir 	Any& rValue,
50cdf0e10cSrcweir 	const SvXMLUnitConverter& rUnitConverter ) const
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	if( (rStrImpValue.indexOf( sal_Unicode('%') ) != -1) != mbPercent )
53cdf0e10cSrcweir 		return sal_False;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	sal_Int32 nValue;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	if( mbPercent )
58cdf0e10cSrcweir 	{
59cdf0e10cSrcweir 		if( !rUnitConverter.convertPercent( nValue, rStrImpValue ) )
60cdf0e10cSrcweir 			return sal_False;
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir 	else
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 		if( !rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
65cdf0e10cSrcweir 			return sal_False;
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	rValue <<= nValue;
69cdf0e10cSrcweir 	return sal_True;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const72cdf0e10cSrcweir sal_Bool XMLPercentOrMeasurePropertyHandler::exportXML(
73cdf0e10cSrcweir 	OUString& rStrExpValue,
74cdf0e10cSrcweir 	const Any& rValue,
75cdf0e10cSrcweir 	const SvXMLUnitConverter& rUnitConverter ) const
76cdf0e10cSrcweir {
77cdf0e10cSrcweir   	OUStringBuffer aOut;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 	sal_Int32 nValue = 0;
80cdf0e10cSrcweir 	if( !(rValue >>= nValue ) )
81cdf0e10cSrcweir 		return sal_False;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	if( mbPercent )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 	 	rUnitConverter.convertPercent( aOut, nValue );
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 	else
88cdf0e10cSrcweir 	{
89cdf0e10cSrcweir 	 	rUnitConverter.convertMeasure( aOut, nValue );
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
93cdf0e10cSrcweir 	return sal_True;
94cdf0e10cSrcweir }
95