xref: /AOO41X/main/xmloff/source/style/XMLPercentOrMeasurePropertyHandler.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
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 <tools/debug.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include "XMLPercentOrMeasurePropertyHandler.hxx"
30 #include <xmloff/xmluconv.hxx>
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using ::rtl::OUString;
35 using ::rtl::OUStringBuffer;
36 
37 
XMLPercentOrMeasurePropertyHandler(sal_Bool bPercent)38 XMLPercentOrMeasurePropertyHandler::XMLPercentOrMeasurePropertyHandler( sal_Bool bPercent )
39 : mbPercent( bPercent )
40 {
41 }
42 
~XMLPercentOrMeasurePropertyHandler()43 XMLPercentOrMeasurePropertyHandler::~XMLPercentOrMeasurePropertyHandler()
44 {
45 }
46 
importXML(const OUString & rStrImpValue,Any & rValue,const SvXMLUnitConverter & rUnitConverter) const47 sal_Bool XMLPercentOrMeasurePropertyHandler::importXML(
48     const OUString& rStrImpValue,
49     Any& rValue,
50     const SvXMLUnitConverter& rUnitConverter ) const
51 {
52     if( (rStrImpValue.indexOf( sal_Unicode('%') ) != -1) != mbPercent )
53         return sal_False;
54 
55     sal_Int32 nValue;
56 
57     if( mbPercent )
58     {
59         if( !rUnitConverter.convertPercent( nValue, rStrImpValue ) )
60             return sal_False;
61     }
62     else
63     {
64         if( !rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
65             return sal_False;
66     }
67 
68     rValue <<= nValue;
69     return sal_True;
70 }
71 
exportXML(OUString & rStrExpValue,const Any & rValue,const SvXMLUnitConverter & rUnitConverter) const72 sal_Bool XMLPercentOrMeasurePropertyHandler::exportXML(
73     OUString& rStrExpValue,
74     const Any& rValue,
75     const SvXMLUnitConverter& rUnitConverter ) const
76 {
77     OUStringBuffer aOut;
78 
79     sal_Int32 nValue = 0;
80     if( !(rValue >>= nValue ) )
81         return sal_False;
82 
83     if( mbPercent )
84     {
85         rUnitConverter.convertPercent( aOut, nValue );
86     }
87     else
88     {
89         rUnitConverter.convertMeasure( aOut, nValue );
90     }
91 
92     rStrExpValue = aOut.makeStringAndClear();
93     return sal_True;
94 }
95