xref: /trunk/main/xmloff/source/draw/propimp0.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 #include <tools/string.hxx>
31 #include <rtl/ustrbuf.hxx>
32 #include "propimp0.hxx"
33 #include <com/sun/star/drawing/LineDash.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
35 #include <com/sun/star/uno/Any.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/xmlimp.hxx>
38 
39 using ::rtl::OUString;
40 using ::rtl::OUStringBuffer;
41 
42 using namespace ::com::sun::star;
43 
44 //////////////////////////////////////////////////////////////////////////////
45 // implementation of graphic property Stroke
46 
47 
48 //////////////////////////////////////////////////////////////////////////////
49 // implementation of presentation page property Change
50 
51 //////////////////////////////////////////////////////////////////////////////
52 // implementation of an effect duration property handler
53 
54 
55 XMLDurationPropertyHdl::~XMLDurationPropertyHdl()
56 {
57 }
58 
59 sal_Bool XMLDurationPropertyHdl::importXML(
60 	const OUString& rStrImpValue,
61 	::com::sun::star::uno::Any& rValue,
62 	const SvXMLUnitConverter& ) const
63 {
64 	util::DateTime aTime;
65 	SvXMLUnitConverter::convertTime( aTime,  rStrImpValue );
66 
67 	const sal_Int32 nSeconds = ( aTime.Hours * 60 + aTime.Minutes ) * 60 + aTime.Seconds;
68 	rValue <<= nSeconds;
69 
70 	return sal_True;
71 }
72 
73 sal_Bool XMLDurationPropertyHdl::exportXML(
74 	OUString& rStrExpValue,
75 	const ::com::sun::star::uno::Any& rValue,
76 	const SvXMLUnitConverter& ) const
77 {
78 	sal_Int32 nVal = 0;
79 
80 	if(rValue >>= nVal)
81 	{
82 		util::DateTime aTime( 0, (sal_uInt16)nVal, 0, 0, 0, 0, 0 );
83 
84 		OUStringBuffer aOut;
85 		SvXMLUnitConverter::convertTime( aOut, aTime );
86 		rStrExpValue = aOut.makeStringAndClear();
87 		return sal_True;
88 	}
89 
90 	return sal_False;
91 }
92 
93 //////////////////////////////////////////////////////////////////////////////
94 // implementation of an opacity property handler
95 
96 
97 XMLOpacityPropertyHdl::XMLOpacityPropertyHdl( SvXMLImport* pImport )
98 : mpImport( pImport )
99 {
100 }
101 
102 XMLOpacityPropertyHdl::~XMLOpacityPropertyHdl()
103 {
104 }
105 
106 sal_Bool XMLOpacityPropertyHdl::importXML(
107 	const OUString& rStrImpValue,
108 	::com::sun::star::uno::Any& rValue,
109 	const SvXMLUnitConverter& ) const
110 {
111 	sal_Bool bRet = sal_False;
112 	sal_Int32 nValue = 0;
113 
114 	if( rStrImpValue.indexOf( sal_Unicode('%') ) != -1 )
115 	{
116 		if( SvXMLUnitConverter::convertPercent( nValue, rStrImpValue ) )
117 			bRet = sal_True;
118 	}
119 	else
120 	{
121 		nValue = sal_Int32( rStrImpValue.toDouble() * 100.0 );
122 		bRet = sal_True;
123 	}
124 
125 	if( bRet )
126 	{
127 		// check ranges
128 		if( nValue < 0 )
129 			nValue = 0;
130 		if( nValue > 100 )
131 			nValue = 100;
132 
133 		// convert xml opacity to api transparency
134 		nValue = 100 - nValue;
135 
136 		// #i42959#
137 		if( mpImport )
138 		{
139 			sal_Int32 nUPD, nBuild;
140 			if( mpImport->getBuildIds( nUPD, nBuild ) )
141 			{
142 				// correct import of documents written prior to StarOffice 8/OOO 2.0 final
143 				if( (nUPD == 680) && (nBuild < 8951) )
144 					nValue = 100 - nValue;
145 			}
146 		}
147 
148 		rValue <<= sal_uInt16(nValue);
149 	}
150 
151 	return bRet;
152 }
153 
154 sal_Bool XMLOpacityPropertyHdl::exportXML(
155 	OUString& rStrExpValue,
156 	const ::com::sun::star::uno::Any& rValue,
157 	const SvXMLUnitConverter& ) const
158 {
159 	sal_Bool bRet = sal_False;
160 	sal_uInt16 nVal = sal_uInt16();
161 
162 	if( rValue >>= nVal )
163 	{
164 		OUStringBuffer aOut;
165 
166 		nVal = 100 - nVal;
167 		SvXMLUnitConverter::convertPercent( aOut, nVal );
168 		rStrExpValue = aOut.makeStringAndClear();
169 		bRet = sal_True;
170 	}
171 
172 	return bRet;
173 }
174 
175 //////////////////////////////////////////////////////////////////////////////
176 // implementation of an text animation step amount
177 
178 XMLTextAnimationStepPropertyHdl::~XMLTextAnimationStepPropertyHdl()
179 {
180 }
181 
182 sal_Bool XMLTextAnimationStepPropertyHdl::importXML(
183 	const OUString& rStrImpValue,
184 	::com::sun::star::uno::Any& rValue,
185 	const SvXMLUnitConverter& rUnitConverter ) const
186 {
187 	sal_Bool bRet = sal_False;
188 	sal_Int32 nValue = 0;
189 
190 	const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
191 	sal_Int32 nPos = rStrImpValue.indexOf( aPX );
192 	if( nPos != -1 )
193 	{
194 		if( rUnitConverter.convertNumber( nValue, rStrImpValue.copy( 0, nPos ) ) )
195 		{
196 			rValue <<= sal_Int16( -nValue );
197 			bRet = sal_True;
198 		}
199 	}
200 	else
201 	{
202 		if( rUnitConverter.convertMeasure( nValue, rStrImpValue ) )
203 		{
204 			rValue <<= sal_Int16( nValue );
205 			bRet = sal_True;
206 		}
207 	}
208 
209 	return bRet;
210 }
211 
212 sal_Bool XMLTextAnimationStepPropertyHdl::exportXML(
213 	OUString& rStrExpValue,
214 	const ::com::sun::star::uno::Any& rValue,
215 	const SvXMLUnitConverter& rUnitConverter ) const
216 {
217 	sal_Bool bRet = sal_False;
218 	sal_Int16 nVal = sal_Int16();
219 
220 	if( rValue >>= nVal )
221 	{
222 		OUStringBuffer aOut;
223 
224 		if( nVal < 0 )
225 		{
226 			const OUString aPX( RTL_CONSTASCII_USTRINGPARAM( "px" ) );
227 			rUnitConverter.convertNumber( aOut, (sal_Int32)-nVal );
228 			aOut.append( aPX );
229 		}
230 		else
231 		{
232 			rUnitConverter.convertMeasure( aOut, nVal );
233 		}
234 
235 		rStrExpValue = aOut.makeStringAndClear();
236 		bRet = sal_True;
237 	}
238 
239 	return bRet;
240 }
241 
242 //////////////////////////////////////////////////////////////////////////////
243 
244 #include "sdxmlexp_impl.hxx"
245 
246 XMLDateTimeFormatHdl::XMLDateTimeFormatHdl( SvXMLExport* pExport )
247 : mpExport( pExport )
248 {
249 }
250 
251 XMLDateTimeFormatHdl::~XMLDateTimeFormatHdl()
252 {
253 }
254 
255 sal_Bool XMLDateTimeFormatHdl::importXML( const rtl::OUString& rStrImpValue, ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
256 {
257 	rValue <<= rStrImpValue;
258 	return true;
259 }
260 
261 sal_Bool XMLDateTimeFormatHdl::exportXML( rtl::OUString& rStrExpValue, const ::com::sun::star::uno::Any& rValue, const SvXMLUnitConverter& ) const
262 {
263 	sal_Int32 nNumberFormat = 0;
264 	if( mpExport && (rValue >>= nNumberFormat) )
265 	{
266 		mpExport->addDataStyle( nNumberFormat );
267 		rStrExpValue = mpExport->getDataStyleName( nNumberFormat );
268 		return sal_True;
269 	}
270 
271 	return sal_False;
272 }
273