merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / escphdl.cxx
blob5131ad4dd1b1bd36d57e3138eeee37741a34791e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: escphdl.cxx,v $
10 * $Revision: 1.11 $
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>
43 #endif
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()
63 // nothing to do
66 sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
68 sal_Int16 nVal;
70 SvXMLTokenEnumerator aTokens( rStrImpValue );
72 OUString aToken;
73 if( ! aTokens.getNextToken( aToken ) )
74 return sal_False;
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;
84 else
86 sal_Int32 nNewEsc;
87 if( !SvXMLUnitConverter::convertPercent( nNewEsc, aToken ) )
88 return sal_False;
90 nVal = (sal_Int16) nNewEsc;
93 rValue <<= nVal;
94 return sal_True;
97 sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
99 sal_Int32 nValue = 0;
100 OUStringBuffer aOut;
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) );
112 else
114 SvXMLUnitConverter::convertPercent( aOut, nValue );
118 rStrExpValue = aOut.makeStringAndClear();
119 return sal_True;
122 ///////////////////////////////////////////////////////////////////////////////
124 // class XMLEscapementHeightPropHdl
127 XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
129 // nothing to do
132 sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
134 if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
135 return sal_False;
137 SvXMLTokenEnumerator aTokens( rStrImpValue );
139 OUString aToken;
140 if( ! aTokens.getNextToken( aToken ) )
141 return sal_False;
143 sal_Int8 nProp;
144 if( aTokens.getNextToken( aToken ) )
146 sal_Int32 nNewProp;
147 if( !SvXMLUnitConverter::convertPercent( nNewProp, aToken ) )
148 return sal_False;
149 nProp = (sal_Int8)nNewProp;
151 else
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#)
156 else
157 nProp = (sal_Int8) DFLT_ESC_PROP;
160 rValue <<= nProp;
161 return sal_True;
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;