bump product version to 4.1.6.2
[LibreOffice.git] / xmloff / source / style / PageMasterPropHdl.cxx
blobd37db396b9b19c8e45cded301f9f8307244c13ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "PageMasterPropHdl.hxx"
23 #include <sax/tools/converter.hxx>
25 #include <xmloff/xmltoken.hxx>
26 #include <xmloff/xmluconv.hxx>
27 #include <xmloff/xmlnumi.hxx>
28 #include <xmloff/xmlnume.hxx>
29 #include <rtl/ustrbuf.hxx>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/style/PageStyleLayout.hpp>
32 #include <comphelper/types.hxx>
33 #include <comphelper/extract.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::style;
39 using namespace ::comphelper;
40 using namespace ::xmloff::token;
43 //______________________________________________________________________________
45 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
48 //______________________________________________________________________________
49 // property handler for style:page-usage (style::PageStyleLayout)
51 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
55 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
57 style::PageStyleLayout eLayout1, eLayout2;
58 return ((rAny1 >>= eLayout1) && (rAny2 >>= eLayout2)) ? (eLayout1 == eLayout2) : sal_False;
61 sal_Bool XMLPMPropHdl_PageStyleLayout::importXML(
62 const OUString& rStrImpValue,
63 Any& rValue,
64 const SvXMLUnitConverter& ) const
66 sal_Bool bRet = sal_True;
68 if( IsXMLToken( rStrImpValue, XML_ALL ) )
69 rValue <<= PageStyleLayout_ALL;
70 else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
71 rValue <<= PageStyleLayout_LEFT;
72 else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
73 rValue <<= PageStyleLayout_RIGHT;
74 else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
75 rValue <<= PageStyleLayout_MIRRORED;
76 else
77 bRet = sal_False;
79 return bRet;
82 sal_Bool XMLPMPropHdl_PageStyleLayout::exportXML(
83 OUString& rStrExpValue,
84 const Any& rValue,
85 const SvXMLUnitConverter& ) const
87 sal_Bool bRet = sal_False;
88 PageStyleLayout eLayout;
90 if( rValue >>= eLayout )
92 bRet = sal_True;
93 switch( eLayout )
95 case PageStyleLayout_ALL:
96 rStrExpValue = GetXMLToken( XML_ALL );
97 break;
98 case PageStyleLayout_LEFT:
99 rStrExpValue = GetXMLToken( XML_LEFT );
100 break;
101 case PageStyleLayout_RIGHT:
102 rStrExpValue = GetXMLToken( XML_RIGHT );
103 break;
104 case PageStyleLayout_MIRRORED:
105 rStrExpValue = GetXMLToken( XML_MIRRORED );
106 break;
107 default:
108 bRet = sal_False;
112 return bRet;
116 //______________________________________________________________________________
117 // property handler for style:num-format (style::NumberingType)
119 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
123 sal_Bool XMLPMPropHdl_NumFormat::importXML(
124 const OUString& rStrImpValue,
125 Any& rValue,
126 const SvXMLUnitConverter& rUnitConverter ) const
128 sal_Int16 nSync = sal_Int16();
129 sal_Int16 nNumType = NumberingType::NUMBER_NONE;
130 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(),
131 sal_True );
133 if( !(rValue >>= nSync) )
134 nSync = NumberingType::NUMBER_NONE;
136 // if num-letter-sync appears before num-format, the function
137 // XMLPMPropHdl_NumLetterSync::importXML() sets the value
138 // NumberingType::CHARS_LOWER_LETTER_N
139 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
141 switch( nNumType )
143 case NumberingType::CHARS_LOWER_LETTER:
144 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
145 break;
146 case NumberingType::CHARS_UPPER_LETTER:
147 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
148 break;
151 rValue <<= nNumType;
153 return sal_True;
156 sal_Bool XMLPMPropHdl_NumFormat::exportXML(
157 OUString& rStrExpValue,
158 const Any& rValue,
159 const SvXMLUnitConverter& rUnitConverter ) const
161 sal_Bool bRet = sal_False;
162 sal_Int16 nNumType = sal_Int16();
164 if( rValue >>= nNumType )
166 OUStringBuffer aBuffer( 10 );
167 rUnitConverter.convertNumFormat( aBuffer, nNumType );
168 rStrExpValue = aBuffer.makeStringAndClear();
169 bRet = sal_True;
171 return bRet;
175 //______________________________________________________________________________
176 // property handler for style:num-letter-sync (style::NumberingType)
178 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
182 sal_Bool XMLPMPropHdl_NumLetterSync::importXML(
183 const OUString& rStrImpValue,
184 Any& rValue,
185 const SvXMLUnitConverter& rUnitConverter ) const
187 sal_Int16 nNumType;
188 sal_Int16 nSync = NumberingType::NUMBER_NONE;
189 rUnitConverter.convertNumFormat( nSync, rStrImpValue,
190 GetXMLToken( XML_A ), sal_True );
192 if( !(rValue >>= nNumType) )
193 nNumType = NumberingType::NUMBER_NONE;
195 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
197 switch( nNumType )
199 case NumberingType::CHARS_LOWER_LETTER:
200 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
201 break;
202 case NumberingType::CHARS_UPPER_LETTER:
203 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
204 break;
207 rValue <<= nNumType;
209 return sal_True;
212 sal_Bool XMLPMPropHdl_NumLetterSync::exportXML(
213 OUString& rStrExpValue,
214 const Any& rValue,
215 const SvXMLUnitConverter& rUnitConverter ) const
217 sal_Bool bRet = sal_False;
218 sal_Int16 nNumType = sal_Int16();
220 if( rValue >>= nNumType )
222 OUStringBuffer aBuffer( 5 );
223 rUnitConverter.convertNumLetterSync( aBuffer, nNumType );
224 rStrExpValue = aBuffer.makeStringAndClear();
225 bRet = !rStrExpValue.isEmpty();
227 return bRet;
231 //______________________________________________________________________________
232 // property handler for style:paper-tray-number
234 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
238 sal_Bool XMLPMPropHdl_PaperTrayNumber::importXML(
239 const OUString& rStrImpValue,
240 Any& rValue,
241 const SvXMLUnitConverter& ) const
243 sal_Bool bRet = sal_False;
245 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
247 rValue <<= DEFAULT_PAPERTRAY;
248 bRet = sal_True;
250 else
252 sal_Int32 nPaperTray;
253 if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
255 rValue <<= nPaperTray;
256 bRet = sal_True;
260 return bRet;
263 sal_Bool XMLPMPropHdl_PaperTrayNumber::exportXML(
264 OUString& rStrExpValue,
265 const Any& rValue,
266 const SvXMLUnitConverter& ) const
268 sal_Bool bRet = sal_False;
269 sal_Int32 nPaperTray = 0;
271 if( rValue >>= nPaperTray )
273 if( nPaperTray == DEFAULT_PAPERTRAY )
274 rStrExpValue = GetXMLToken( XML_DEFAULT );
275 else
277 OUStringBuffer aBuffer;
278 ::sax::Converter::convertNumber( aBuffer, nPaperTray );
279 rStrExpValue = aBuffer.makeStringAndClear();
281 bRet = sal_True;
283 return bRet;
287 //______________________________________________________________________________
288 // property handler for style:print
290 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
291 sAttrValue( GetXMLToken( eValue ) )
295 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
299 sal_Bool XMLPMPropHdl_Print::importXML(
300 const OUString& rStrImpValue,
301 Any& rValue,
302 const SvXMLUnitConverter& ) const
304 sal_Unicode cToken = ' ';
305 sal_Int32 nTokenIndex = 0;
306 sal_Bool bFound = sal_False;
310 bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
312 while ( (nTokenIndex >= 0) && !bFound );
314 setBOOL( rValue, bFound );
315 return sal_True;
318 sal_Bool XMLPMPropHdl_Print::exportXML(
319 OUString& rStrExpValue,
320 const Any& rValue,
321 const SvXMLUnitConverter& ) const
323 if( getBOOL( rValue ) )
325 if( !rStrExpValue.isEmpty() )
326 rStrExpValue += " ";
327 rStrExpValue += sAttrValue;
330 return sal_True;
333 //______________________________________________________________________________
334 // property handler for style:table-centering
336 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
340 sal_Bool XMLPMPropHdl_CenterHorizontal::importXML(
341 const OUString& rStrImpValue,
342 Any& rValue,
343 const SvXMLUnitConverter& ) const
345 sal_Bool bRet = sal_False;
347 if (!rStrImpValue.isEmpty())
348 if (IsXMLToken( rStrImpValue, XML_BOTH) ||
349 IsXMLToken( rStrImpValue, XML_HORIZONTAL))
351 rValue = ::cppu::bool2any(sal_True);
352 bRet = sal_True;
356 return bRet;
359 sal_Bool XMLPMPropHdl_CenterHorizontal::exportXML(
360 OUString& rStrExpValue,
361 const Any& rValue,
362 const SvXMLUnitConverter& ) const
364 sal_Bool bRet = sal_False;
366 if ( ::cppu::any2bool( rValue ) )
368 bRet = sal_True;
369 if (!rStrExpValue.isEmpty())
370 rStrExpValue = GetXMLToken(XML_BOTH);
371 else
372 rStrExpValue = GetXMLToken(XML_HORIZONTAL);
375 return bRet;
378 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
382 sal_Bool XMLPMPropHdl_CenterVertical::importXML(
383 const OUString& rStrImpValue,
384 Any& rValue,
385 const SvXMLUnitConverter& ) const
387 sal_Bool bRet = sal_False;
389 if (!rStrImpValue.isEmpty())
390 if (IsXMLToken(rStrImpValue, XML_BOTH) ||
391 IsXMLToken(rStrImpValue, XML_VERTICAL) )
393 rValue = ::cppu::bool2any(sal_True);
394 bRet = sal_True;
397 return bRet;
400 sal_Bool XMLPMPropHdl_CenterVertical::exportXML(
401 OUString& rStrExpValue,
402 const Any& rValue,
403 const SvXMLUnitConverter& ) const
405 sal_Bool bRet = sal_False;
407 if ( ::cppu::any2bool( rValue ) )
409 bRet = sal_True;
410 if (!rStrExpValue.isEmpty())
411 rStrExpValue = GetXMLToken(XML_BOTH);
412 else
413 rStrExpValue = GetXMLToken(XML_VERTICAL);
416 return bRet;
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */