xref: /aoo42x/main/xmloff/source/style/escphdl.cxx (revision 63bba73c)
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 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <escphdl.hxx>
29cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
30cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using ::rtl::OUString;
35cdf0e10cSrcweir using ::rtl::OUStringBuffer;
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir using namespace ::xmloff::token;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // this is a copy of defines in svx/inc/escpitem.hxx
41cdf0e10cSrcweir #define DFLT_ESC_PROP	 58
42cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUPER	101
43cdf0e10cSrcweir #define DFLT_ESC_AUTO_SUB  -101
44cdf0e10cSrcweir 
45cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
46cdf0e10cSrcweir //
47cdf0e10cSrcweir // class XMLEscapementPropHdl
48cdf0e10cSrcweir //
49cdf0e10cSrcweir 
~XMLEscapementPropHdl()50cdf0e10cSrcweir XMLEscapementPropHdl::~XMLEscapementPropHdl()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	// nothing to do
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const55cdf0e10cSrcweir sal_Bool XMLEscapementPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir 	sal_Int16 nVal;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	SvXMLTokenEnumerator aTokens( rStrImpValue );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	OUString aToken;
62cdf0e10cSrcweir 	if( ! aTokens.getNextToken( aToken ) )
63cdf0e10cSrcweir 		return sal_False;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	if( IsXMLToken( aToken, XML_ESCAPEMENT_SUB ) )
66cdf0e10cSrcweir 	{
67cdf0e10cSrcweir 		nVal = DFLT_ESC_AUTO_SUB;
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir 	else if( IsXMLToken( aToken, XML_ESCAPEMENT_SUPER ) )
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 		nVal = DFLT_ESC_AUTO_SUPER;
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir 	else
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		sal_Int32 nNewEsc;
76cdf0e10cSrcweir 		if( !SvXMLUnitConverter::convertPercent( nNewEsc, aToken ) )
77cdf0e10cSrcweir 			return sal_False;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		nVal = (sal_Int16) nNewEsc;
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	rValue <<= nVal;
83cdf0e10cSrcweir 	return sal_True;
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const86cdf0e10cSrcweir sal_Bool XMLEscapementPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	sal_Int32 nValue = 0;
89cdf0e10cSrcweir 	OUStringBuffer aOut;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	if( rValue >>= nValue )
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		if( nValue == DFLT_ESC_AUTO_SUPER )
94cdf0e10cSrcweir 		{
95cdf0e10cSrcweir 			aOut.append( GetXMLToken(XML_ESCAPEMENT_SUPER) );
96cdf0e10cSrcweir 		}
97cdf0e10cSrcweir 		else if( nValue == DFLT_ESC_AUTO_SUB )
98cdf0e10cSrcweir 		{
99cdf0e10cSrcweir 			aOut.append( GetXMLToken(XML_ESCAPEMENT_SUB) );
100cdf0e10cSrcweir 		}
101cdf0e10cSrcweir 		else
102cdf0e10cSrcweir 		{
103cdf0e10cSrcweir 			SvXMLUnitConverter::convertPercent( aOut, nValue );
104cdf0e10cSrcweir 		}
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
108cdf0e10cSrcweir 	return sal_True;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////////
112cdf0e10cSrcweir //
113cdf0e10cSrcweir // class XMLEscapementHeightPropHdl
114cdf0e10cSrcweir //
115cdf0e10cSrcweir 
~XMLEscapementHeightPropHdl()116cdf0e10cSrcweir XMLEscapementHeightPropHdl::~XMLEscapementHeightPropHdl()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	// nothing to do
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
importXML(const OUString & rStrImpValue,uno::Any & rValue,const SvXMLUnitConverter &) const121cdf0e10cSrcweir sal_Bool XMLEscapementHeightPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	if( IsXMLToken( rStrImpValue, XML_CASEMAP_SMALL_CAPS ) )
124cdf0e10cSrcweir 		return sal_False;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	SvXMLTokenEnumerator aTokens( rStrImpValue );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	OUString aToken;
129cdf0e10cSrcweir 	if( ! aTokens.getNextToken( aToken ) )
130cdf0e10cSrcweir 		return sal_False;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	sal_Int8 nProp;
133cdf0e10cSrcweir 	if( aTokens.getNextToken( aToken ) )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		sal_Int32 nNewProp;
136cdf0e10cSrcweir 		if( !SvXMLUnitConverter::convertPercent( nNewProp, aToken ) )
137cdf0e10cSrcweir 			return sal_False;
138cdf0e10cSrcweir 		nProp = (sal_Int8)nNewProp;
139cdf0e10cSrcweir 	}
140cdf0e10cSrcweir 	else
141cdf0e10cSrcweir 	{
142cdf0e10cSrcweir         sal_Int32 nEscapementPosition=0;
143cdf0e10cSrcweir         if( SvXMLUnitConverter::convertPercent( nEscapementPosition, aToken ) && nEscapementPosition==0 )
144cdf0e10cSrcweir             nProp = 100; //if escapement position is zero and no escapement height is given the default height should be 100percent and not something smaller (#i91800#)
145cdf0e10cSrcweir         else
146cdf0e10cSrcweir             nProp = (sal_Int8) DFLT_ESC_PROP;
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	rValue <<= nProp;
150cdf0e10cSrcweir 	return sal_True;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
exportXML(OUString & rStrExpValue,const uno::Any & rValue,const SvXMLUnitConverter &) const153cdf0e10cSrcweir sal_Bool XMLEscapementHeightPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
154cdf0e10cSrcweir {
155cdf0e10cSrcweir 	OUStringBuffer aOut( rStrExpValue );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	sal_Int32 nValue = 0;
158cdf0e10cSrcweir 	if( rValue >>= nValue )
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		if( rStrExpValue.getLength() )
161cdf0e10cSrcweir 			aOut.append( sal_Unicode(' '));
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 		SvXMLUnitConverter::convertPercent( aOut, nValue );
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	rStrExpValue = aOut.makeStringAndClear();
167cdf0e10cSrcweir 	return rStrExpValue.getLength() != 0;
168cdf0e10cSrcweir }
169