merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / lspachdl.cxx
blob7c3638ede2f4eefc1ffcbae57e1473daa3043fb4
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: lspachdl.cxx,v $
10 * $Revision: 1.9 $
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 <lspachdl.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <xmloff/xmluconv.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/style/LineSpacing.hpp>
41 #include <com/sun/star/style/LineSpacingMode.hpp>
43 #ifndef _XMLOFF_XMLEMENT_HXX
44 #include <xmloff/xmlelement.hxx>
45 #endif
47 using ::rtl::OUString;
48 using ::rtl::OUStringBuffer;
50 using namespace ::com::sun::star;
51 using ::xmloff::token::IsXMLToken;
52 using ::xmloff::token::XML_CASEMAP_NORMAL;
54 // this is a copy of defines in svx/inc/escpitem.hxx
55 #define DFLT_ESC_PROP 58
56 #define DFLT_ESC_AUTO_SUPER 101
57 #define DFLT_ESC_AUTO_SUB -101
59 ///////////////////////////////////////////////////////////////////////////////
61 // class XMLEscapementPropHdl
64 XMLLineHeightHdl::~XMLLineHeightHdl()
66 // nothing to do
69 sal_Bool XMLLineHeightHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
71 style::LineSpacing aLSp;
72 sal_Int32 nTemp = 0;
74 if( -1 != rStrImpValue.indexOf( sal_Unicode( '%' ) ) )
76 aLSp.Mode = style::LineSpacingMode::PROP;
77 if(!rUnitConverter.convertPercent( nTemp, rStrImpValue ))
78 return sal_False;
79 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
81 else if( IsXMLToken( rStrImpValue, XML_CASEMAP_NORMAL) )
83 aLSp.Mode = style::LineSpacingMode::PROP;
84 aLSp.Height = 100;
86 else
88 aLSp.Mode = style::LineSpacingMode::FIX;
89 if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
90 return sal_False;
91 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
94 rValue <<= aLSp;
95 return sal_True;
98 sal_Bool XMLLineHeightHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
100 OUStringBuffer aOut;
102 style::LineSpacing aLSp;
103 if(!(rValue >>= aLSp))
104 return sal_False;
106 if( style::LineSpacingMode::PROP != aLSp.Mode && style::LineSpacingMode::FIX != aLSp.Mode )
107 return sal_False;
109 if( style::LineSpacingMode::PROP == aLSp.Mode )
111 rUnitConverter.convertPercent( aOut, aLSp.Height );
113 else
115 rUnitConverter.convertMeasure( aOut, aLSp.Height );
118 rStrExpValue = aOut.makeStringAndClear();
119 return rStrExpValue.getLength() != 0;
122 ///////////////////////////////////////////////////////////////////////////////
124 // class XMLLineHeightAtLeastHdl
127 XMLLineHeightAtLeastHdl::~XMLLineHeightAtLeastHdl()
129 // nothing to do
132 sal_Bool XMLLineHeightAtLeastHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
134 style::LineSpacing aLSp;
136 sal_Int32 nTemp;
137 aLSp.Mode = style::LineSpacingMode::MINIMUM;
138 if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
139 return sal_False;
140 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
142 rValue <<= aLSp;
143 return sal_True;
146 sal_Bool XMLLineHeightAtLeastHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
148 OUStringBuffer aOut;
150 style::LineSpacing aLSp;
151 if(!(rValue >>= aLSp))
152 return sal_False;
154 if( style::LineSpacingMode::MINIMUM != aLSp.Mode )
155 return sal_False;
157 rUnitConverter.convertMeasure( aOut, aLSp.Height );
159 rStrExpValue = aOut.makeStringAndClear();
160 return rStrExpValue.getLength() != 0;
163 ///////////////////////////////////////////////////////////////////////////////
165 // class XMLLineSpacingHdl
168 XMLLineSpacingHdl::~XMLLineSpacingHdl()
170 // nothing to do
173 sal_Bool XMLLineSpacingHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
175 style::LineSpacing aLSp;
176 sal_Int32 nTemp;
178 aLSp.Mode = style::LineSpacingMode::LEADING;
179 if(!rUnitConverter.convertMeasure( nTemp, rStrImpValue, 0x0000, 0xffff ))
180 return sal_False;
181 aLSp.Height = sal::static_int_cast< sal_Int16 >(nTemp);
183 rValue <<= aLSp;
184 return sal_True;
187 sal_Bool XMLLineSpacingHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& rUnitConverter ) const
189 OUStringBuffer aOut;
191 style::LineSpacing aLSp;
192 if(!(rValue >>= aLSp))
193 return sal_False;
195 if( style::LineSpacingMode::LEADING != aLSp.Mode )
196 return sal_False;
198 rUnitConverter.convertMeasure( aOut, aLSp.Height );
200 rStrExpValue = aOut.makeStringAndClear();
201 return rStrExpValue.getLength() != 0;