merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / PageMasterPropHdl.cxx
blob1dc3420d398099cf29898bba8f48ff56566efe85
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: PageMasterPropHdl.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 "PageMasterPropHdl.hxx"
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmluconv.hxx>
36 #include <xmloff/xmlnumi.hxx>
37 #include <xmloff/xmlnume.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <com/sun/star/uno/Any.hxx>
40 #include <com/sun/star/style/PageStyleLayout.hpp>
41 #include <comphelper/types.hxx>
42 #include <comphelper/extract.hxx>
44 using ::rtl::OUString;
45 using ::rtl::OUStringBuffer;
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::style;
50 using namespace ::comphelper;
51 using namespace ::xmloff::token;
54 //______________________________________________________________________________
56 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
59 //______________________________________________________________________________
60 // property handler for style:page-usage (style::PageStyleLayout)
62 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
66 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
68 style::PageStyleLayout eLayout1, eLayout2;
69 return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False;
72 sal_Bool XMLPMPropHdl_PageStyleLayout::importXML(
73 const OUString& rStrImpValue,
74 Any& rValue,
75 const SvXMLUnitConverter& ) const
77 sal_Bool bRet = sal_True;
79 if( IsXMLToken( rStrImpValue, XML_ALL ) )
80 rValue <<= PageStyleLayout_ALL;
81 else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
82 rValue <<= PageStyleLayout_LEFT;
83 else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
84 rValue <<= PageStyleLayout_RIGHT;
85 else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
86 rValue <<= PageStyleLayout_MIRRORED;
87 else
88 bRet = sal_False;
90 return bRet;
93 sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML(
94 OUString& rStrExpValue,
95 const Any& rValue,
96 const SvXMLUnitConverter& ) const
98 sal_Bool bRet = sal_False;
99 PageStyleLayout eLayout;
101 if( rValue >>= eLayout )
103 bRet = sal_True;
104 switch( eLayout )
106 case PageStyleLayout_ALL:
107 rStrExpValue = GetXMLToken( XML_ALL );
108 break;
109 case PageStyleLayout_LEFT:
110 rStrExpValue = GetXMLToken( XML_LEFT );
111 break;
112 case PageStyleLayout_RIGHT:
113 rStrExpValue = GetXMLToken( XML_RIGHT );
114 break;
115 case PageStyleLayout_MIRRORED:
116 rStrExpValue = GetXMLToken( XML_MIRRORED );
117 break;
118 default:
119 bRet = sal_False;
123 return bRet;
127 //______________________________________________________________________________
128 // property handler for style:num-format (style::NumberingType)
130 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
134 sal_Bool XMLPMPropHdl_NumFormat::importXML(
135 const OUString& rStrImpValue,
136 Any& rValue,
137 const SvXMLUnitConverter& rUnitConverter ) const
139 sal_Int16 nSync = sal_Int16();
140 sal_Int16 nNumType = NumberingType::NUMBER_NONE;
141 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(),
142 sal_True );
144 if( !(rValue >>= nSync) )
145 nSync = NumberingType::NUMBER_NONE;
147 // if num-letter-sync appears before num-format, the function
148 // XMLPMPropHdl_NumLetterSync::importXML() sets the value
149 // NumberingType::CHARS_LOWER_LETTER_N
150 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
152 switch( nNumType )
154 case NumberingType::CHARS_LOWER_LETTER:
155 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
156 break;
157 case NumberingType::CHARS_UPPER_LETTER:
158 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
159 break;
162 rValue <<= nNumType;
164 return sal_True;
167 sal_Bool XMLPMPropHdl_NumFormat::exportXML(
168 OUString& rStrExpValue,
169 const Any& rValue,
170 const SvXMLUnitConverter& rUnitConverter ) const
172 sal_Bool bRet = sal_False;
173 sal_Int16 nNumType = sal_Int16();
175 if( rValue >>= nNumType )
177 OUStringBuffer aBuffer( 10 );
178 rUnitConverter.convertNumFormat( aBuffer, nNumType );
179 rStrExpValue = aBuffer.makeStringAndClear();
180 bRet = sal_True;
182 return bRet;
186 //______________________________________________________________________________
187 // property handler for style:num-letter-sync (style::NumberingType)
189 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
193 sal_Bool XMLPMPropHdl_NumLetterSync::importXML(
194 const OUString& rStrImpValue,
195 Any& rValue,
196 const SvXMLUnitConverter& rUnitConverter ) const
198 sal_Int16 nNumType;
199 sal_Int16 nSync = NumberingType::NUMBER_NONE;
200 rUnitConverter.convertNumFormat( nSync, rStrImpValue,
201 GetXMLToken( XML_A ), sal_True );
203 if( !(rValue >>= nNumType) )
204 nNumType = NumberingType::NUMBER_NONE;
206 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
208 switch( nNumType )
210 case NumberingType::CHARS_LOWER_LETTER:
211 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
212 break;
213 case NumberingType::CHARS_UPPER_LETTER:
214 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
215 break;
218 rValue <<= nNumType;
220 return sal_True;
223 sal_Bool XMLPMPropHdl_NumLetterSync::exportXML(
224 OUString& rStrExpValue,
225 const Any& rValue,
226 const SvXMLUnitConverter& rUnitConverter ) const
228 sal_Bool bRet = sal_False;
229 sal_Int16 nNumType = sal_Int16();
231 if( rValue >>= nNumType )
233 OUStringBuffer aBuffer( 5 );
234 rUnitConverter.convertNumLetterSync( aBuffer, nNumType );
235 rStrExpValue = aBuffer.makeStringAndClear();
236 bRet = rStrExpValue.getLength() > 0;
238 return bRet;
242 //______________________________________________________________________________
243 // property handler for style:paper-tray-number
245 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
249 sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML(
250 const OUString& rStrImpValue,
251 Any& rValue,
252 const SvXMLUnitConverter& ) const
254 sal_Bool bRet = sal_False;
256 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
258 rValue <<= DEFAULT_PAPERTRAY;
259 bRet = sal_True;
261 else
263 sal_Int32 nPaperTray;
264 if( SvXMLUnitConverter::convertNumber( nPaperTray, rStrImpValue, 0 ) )
266 rValue <<= nPaperTray;
267 bRet = sal_True;
271 return bRet;
274 sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML(
275 OUString& rStrExpValue,
276 const Any& rValue,
277 const SvXMLUnitConverter& ) const
279 sal_Bool bRet = sal_False;
280 sal_Int32 nPaperTray = 0;
282 if( rValue >>= nPaperTray )
284 if( nPaperTray == DEFAULT_PAPERTRAY )
285 rStrExpValue = GetXMLToken( XML_DEFAULT );
286 else
288 OUStringBuffer aBuffer;
289 SvXMLUnitConverter::convertNumber( aBuffer, nPaperTray );
290 rStrExpValue = aBuffer.makeStringAndClear();
292 bRet = sal_True;
294 return bRet;
298 //______________________________________________________________________________
299 // property handler for style:print
301 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
302 sAttrValue( GetXMLToken( eValue ) )
306 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
310 sal_Bool XMLPMPropHdl_Print::importXML(
311 const OUString& rStrImpValue,
312 Any& rValue,
313 const SvXMLUnitConverter& ) const
315 sal_Unicode cToken = ' ';
316 sal_Int32 nTokenIndex = 0;
317 sal_Bool bFound = sal_False;
321 bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
323 while ( (nTokenIndex >= 0) && !bFound );
325 setBOOL( rValue, bFound );
326 return sal_True;
329 sal_Bool XMLPMPropHdl_Print::exportXML(
330 OUString& rStrExpValue,
331 const Any& rValue,
332 const SvXMLUnitConverter& ) const
334 if( getBOOL( rValue ) )
336 if( rStrExpValue.getLength() )
337 rStrExpValue += OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) );
338 rStrExpValue += sAttrValue;
341 return sal_True;
344 //______________________________________________________________________________
345 // property handler for style:table-centering
347 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
351 sal_Bool XMLPMPropHdl_CenterHorizontal::importXML(
352 const OUString& rStrImpValue,
353 Any& rValue,
354 const SvXMLUnitConverter& ) const
356 sal_Bool bRet = sal_False;
358 if (rStrImpValue.getLength())
359 if (IsXMLToken( rStrImpValue, XML_BOTH) ||
360 IsXMLToken( rStrImpValue, XML_HORIZONTAL))
362 rValue = ::cppu::bool2any(sal_True);
363 bRet = sal_True;
367 return bRet;
370 sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML(
371 OUString& rStrExpValue,
372 const Any& rValue,
373 const SvXMLUnitConverter& ) const
375 sal_Bool bRet = sal_False;
377 if ( ::cppu::any2bool( rValue ) )
379 bRet = sal_True;
380 if (rStrExpValue.getLength())
381 rStrExpValue = GetXMLToken(XML_BOTH);
382 else
383 rStrExpValue = GetXMLToken(XML_HORIZONTAL);
386 return bRet;
389 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
393 sal_Bool XMLPMPropHdl_CenterVertical::importXML(
394 const OUString& rStrImpValue,
395 Any& rValue,
396 const SvXMLUnitConverter& ) const
398 sal_Bool bRet = sal_False;
400 if (rStrImpValue.getLength())
401 if (IsXMLToken(rStrImpValue, XML_BOTH) ||
402 IsXMLToken(rStrImpValue, XML_VERTICAL) )
404 rValue = ::cppu::bool2any(sal_True);
405 bRet = sal_True;
408 return bRet;
411 sal_Bool XMLPMPropHdl_CenterVertical::exportXML(
412 OUString& rStrExpValue,
413 const Any& rValue,
414 const SvXMLUnitConverter& ) const
416 sal_Bool bRet = sal_False;
418 if ( ::cppu::any2bool( rValue ) )
420 bRet = sal_True;
421 if (rStrExpValue.getLength())
422 rStrExpValue = GetXMLToken(XML_BOTH);
423 else
424 rStrExpValue = GetXMLToken(XML_VERTICAL);
427 return bRet;