merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / propimp0.cxx
blob5ad2b1ba98e0aa32f0fae6fdb861dd36a333bbbd
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: propimp0.cxx,v $
10 * $Revision: 1.17 $
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"
33 #include <tools/string.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include "propimp0.hxx"
36 #include <com/sun/star/drawing/LineDash.hpp>
37 #include <com/sun/star/util/DateTime.hpp>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <xmloff/xmluconv.hxx>
40 #include <xmloff/xmlimp.hxx>
42 using ::rtl::OUString;
43 using ::rtl::OUStringBuffer;
45 using namespace ::com::sun::star;
47 //////////////////////////////////////////////////////////////////////////////
48 // implementation of graphic property Stroke
51 //////////////////////////////////////////////////////////////////////////////
52 // implementation of presentation page property Change
54 //////////////////////////////////////////////////////////////////////////////
55 // implementation of an effect duration property handler
58 XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
62 sal_Bool XMLDurationPropertyHdl::importXML(
63 const OUString& rStrImpValue,
64 ::com::sun::star::uno::Any& rValue,
65 const SvXMLUnitConverter& ) const
67 util::DateTime aTime;
68 SvXMLUnitConverter::convertTime( aTime, rStrImpValue );
70 const sal_Int32 nSeconds = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
71 rValue <<= nSeconds;
73 return sal_True;
76 sal_Bool XMLDurationPropertyHdl::exportXML(
77 OUString& rStrExpValue,
78 const ::com::sun::star::uno::Any& rValue,
79 const SvXMLUnitConverter& ) const
81 sal_Int32 nVal = 0;
83 if(rValue >>= nVal)
85 util::DateTime aTime( 0, (sal_uInt16)nVal, 0, 0, 0, 0, 0 );
87 OUStringBuffer aOut;
88 SvXMLUnitConverter::convertTime( aOut, aTime );
89 rStrExpValue = aOut.makeStringAndClear();
90 return sal_True;
93 return sal_False;
96 //////////////////////////////////////////////////////////////////////////////
97 // implementation of an opacity property handler
100 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
101 : mpImport( pImport )
105 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
109 sal_Bool XMLOpacityPropertyHdl::importXML(
110 const OUString& rStrImpValue,
111 ::com::sun::star::uno::Any& rValue,
112 const SvXMLUnitConverter& ) const
114 sal_Bool bRet = sal_False;
115 sal_Int32 nValue = 0;
117 if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
119 if( SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ) )
120 bRet = sal_True;
122 else
124 nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
125 bRet = sal_True;
128 if( bRet )
130 // check ranges
131 if( nValue < 0 )
132 nValue = 0;
133 if( nValue > 100 )
134 nValue = 100;
136 // convert xml opacity to api transparency
137 nValue = 100 - nValue;
139 // #i42959#
140 if( mpImport )
142 sal_Int32 nUPD, nBuild;
143 if( mpImport->getBuildIds( nUPD, nBuild ) )
145 // correct import of documents written prior to StarOffice 8/OOO 2.0 final
146 if( (nUPD == 680) && (nBuild < 8951) )
147 nValue = 100 - nValue;
151 rValue <<= sal_uInt16(nValue);
154 return bRet;
157 sal_Bool XMLOpacityPropertyHdl::exportXML(
158 OUString& rStrExpValue,
159 const ::com::sun::star::uno::Any& rValue,
160 const SvXMLUnitConverter& ) const
162 sal_Bool bRet = sal_False;
163 sal_uInt16 nVal = sal_uInt16();
165 if( rValue >>= nVal )
167 OUStringBuffer aOut;
169 nVal = 100 - nVal;
170 SvXMLUnitConverter::convertPercent( aOut, nVal );
171 rStrExpValue = aOut.makeStringAndClear();
172 bRet = sal_True;
175 return bRet;
178 //////////////////////////////////////////////////////////////////////////////
179 // implementation of an text animation step amount
181 XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
185 sal_Bool XMLTextAnimationStepPropertyHdl::importXML(
186 const OUString& rStrImpValue,
187 ::com::sun::star::uno::Any& rValue,
188 const SvXMLUnitConverter& rUnitConverter ) const
190 sal_Bool bRet = sal_False;
191 sal_Int32 nValue = 0;
193 const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
194 sal_Int32 nPos = rStrImpValue.indexOf( aPX );
195 if( nPos != -1 )
197 if( rUnitConverter.convertNumber( nValue, rStrImpValue.copy( 0, nPos ) ) )
199 rValue <<= sal_Int16( -nValue );
200 bRet = sal_True;
203 else
205 if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
207 rValue <<= sal_Int16( nValue );
208 bRet = sal_True;
212 return bRet;
215 sal_Bool XMLTextAnimationStepPropertyHdl::exportXML(
216 OUString& rStrExpValue,
217 const ::com::sun::star::uno::Any& rValue,
218 const SvXMLUnitConverter& rUnitConverter ) const
220 sal_Bool bRet = sal_False;
221 sal_Int16 nVal = sal_Int16();
223 if( rValue >>= nVal )
225 OUStringBuffer aOut;
227 if( nVal < 0 )
229 const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
230 rUnitConverter.convertNumber( aOut, (sal_Int32)-nVal );
231 aOut.append( aPX );
233 else
235 rUnitConverter.convertMeasure( aOut, nVal );
238 rStrExpValue = aOut.makeStringAndClear();
239 bRet = sal_True;
242 return bRet;
245 //////////////////////////////////////////////////////////////////////////////
247 #include "sdxmlexp_impl.hxx"
249 XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
250 : mpExport( pExport )
254 XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
258 sal_Bool XMLDateTimeFormatHdl::importXML( const rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
260 rValue <<= rStrImpValue;
261 return true;
264 sal_Bool XMLDateTimeFormatHdl::exportXML( rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
266 sal_Int32 nNumberFormat = 0;
267 if( mpExport && (rValue >>= nNumberFormat) )
269 mpExport->addDataStyle( nNumberFormat );
270 rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
271 return sal_True;
274 return sal_False;