Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "XMLPercentOrMeasurePropertyHandler.hxx"
31 : :
32 : : #include <rtl/ustrbuf.hxx>
33 : :
34 : : #include <com/sun/star/uno/Any.hxx>
35 : :
36 : : #include <sax/tools/converter.hxx>
37 : :
38 : : #include <xmloff/xmluconv.hxx>
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::com::sun::star::uno;
42 : : using ::rtl::OUString;
43 : : using ::rtl::OUStringBuffer;
44 : :
45 : :
46 : 744 : XMLPercentOrMeasurePropertyHandler::XMLPercentOrMeasurePropertyHandler( sal_Bool bPercent )
47 : 744 : : mbPercent( bPercent )
48 : : {
49 : 744 : }
50 : :
51 : 734 : XMLPercentOrMeasurePropertyHandler::~XMLPercentOrMeasurePropertyHandler()
52 : : {
53 [ - + ]: 1468 : }
54 : :
55 : 0 : sal_Bool XMLPercentOrMeasurePropertyHandler::importXML(
56 : : const OUString& rStrImpValue,
57 : : Any& rValue,
58 : : const SvXMLUnitConverter& rUnitConverter ) const
59 : : {
60 [ # # ]: 0 : if( (rStrImpValue.indexOf( sal_Unicode('%') ) != -1) != mbPercent )
61 : 0 : return sal_False;
62 : :
63 : : sal_Int32 nValue;
64 : :
65 [ # # ]: 0 : if( mbPercent )
66 : : {
67 [ # # ][ # # ]: 0 : if (!::sax::Converter::convertPercent( nValue, rStrImpValue ))
68 : 0 : return sal_False;
69 : : }
70 : : else
71 : : {
72 [ # # ][ # # ]: 0 : if (!rUnitConverter.convertMeasureToCore( nValue, rStrImpValue ))
73 : 0 : return sal_False;
74 : : }
75 : :
76 [ # # ]: 0 : rValue <<= nValue;
77 : 0 : return sal_True;
78 : : }
79 : :
80 : 0 : sal_Bool XMLPercentOrMeasurePropertyHandler::exportXML(
81 : : OUString& rStrExpValue,
82 : : const Any& rValue,
83 : : const SvXMLUnitConverter& rUnitConverter ) const
84 : : {
85 : 0 : OUStringBuffer aOut;
86 : :
87 : 0 : sal_Int32 nValue = 0;
88 [ # # ]: 0 : if( !(rValue >>= nValue ) )
89 : 0 : return sal_False;
90 : :
91 [ # # ]: 0 : if( mbPercent )
92 : : {
93 [ # # ]: 0 : ::sax::Converter::convertPercent( aOut, nValue );
94 : : }
95 : : else
96 : : {
97 [ # # ]: 0 : rUnitConverter.convertMeasureToXML( aOut, nValue );
98 : : }
99 : :
100 [ # # ]: 0 : rStrExpValue = aOut.makeStringAndClear();
101 : 0 : return sal_True;
102 : : }
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|