1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: escphdl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include <escphdl.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
41 #ifndef _XMLOFF_XMLEMENT_HXX
42 #include <xmloff/xmlelement.hxx>
45 using ::rtl::OUString
;
46 using ::rtl::OUStringBuffer
;
48 using namespace ::com::sun::star
;
49 using namespace ::xmloff::token
;
51 // this is a copy of defines in svx/inc/escpitem.hxx
52 #define DFLT_ESC_PROP 58
53 #define DFLT_ESC_AUTO_SUPER 101
54 #define DFLT_ESC_AUTO_SUB -101
56 ///////////////////////////////////////////////////////////////////////////////
58 // class XMLEscapementPropHdl
61 XMLEscapementPropHdl::~XMLEscapementPropHdl()
66 sal_Bool
XMLEscapementPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
70 SvXMLTokenEnumerator
aTokens( rStrImpValue
);
73 if( ! aTokens
.getNextToken( aToken
) )
76 if( IsXMLToken( aToken
, XML_ESCAPEMENT_SUB
) )
78 nVal
= DFLT_ESC_AUTO_SUB
;
80 else if( IsXMLToken( aToken
, XML_ESCAPEMENT_SUPER
) )
82 nVal
= DFLT_ESC_AUTO_SUPER
;
87 if( !SvXMLUnitConverter::convertPercent( nNewEsc
, aToken
) )
90 nVal
= (sal_Int16
) nNewEsc
;
97 sal_Bool
XMLEscapementPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
102 if( rValue
>>= nValue
)
104 if( nValue
== DFLT_ESC_AUTO_SUPER
)
106 aOut
.append( GetXMLToken(XML_ESCAPEMENT_SUPER
) );
108 else if( nValue
== DFLT_ESC_AUTO_SUB
)
110 aOut
.append( GetXMLToken(XML_ESCAPEMENT_SUB
) );
114 SvXMLUnitConverter::convertPercent( aOut
, nValue
);
118 rStrExpValue
= aOut
.makeStringAndClear();
122 ///////////////////////////////////////////////////////////////////////////////
124 // class XMLEscapementHeightPropHdl
127 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
132 sal_Bool
XMLEscapementHeightPropHdl::importXML( const OUString
& rStrImpValue
, uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
134 if( IsXMLToken( rStrImpValue
, XML_CASEMAP_SMALL_CAPS
) )
137 SvXMLTokenEnumerator
aTokens( rStrImpValue
);
140 if( ! aTokens
.getNextToken( aToken
) )
144 if( aTokens
.getNextToken( aToken
) )
147 if( !SvXMLUnitConverter::convertPercent( nNewProp
, aToken
) )
149 nProp
= (sal_Int8
)nNewProp
;
153 sal_Int32 nEscapementPosition
=0;
154 if( SvXMLUnitConverter::convertPercent( nEscapementPosition
, aToken
) && nEscapementPosition
==0 )
155 nProp
= 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
157 nProp
= (sal_Int8
) DFLT_ESC_PROP
;
164 sal_Bool
XMLEscapementHeightPropHdl::exportXML( OUString
& rStrExpValue
, const uno::Any
& rValue
, const SvXMLUnitConverter
& ) const
166 OUStringBuffer
aOut( rStrExpValue
);
168 sal_Int32 nValue
= 0;
169 if( rValue
>>= nValue
)
171 if( rStrExpValue
.getLength() )
172 aOut
.append( sal_Unicode(' '));
174 SvXMLUnitConverter::convertPercent( aOut
, nValue
);
177 rStrExpValue
= aOut
.makeStringAndClear();
178 return rStrExpValue
.getLength() != 0;