bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / PageMasterPropHdl.cxx
blob96968fee69fde7f148d0ac6aa947f553e6cee185
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 .
20 #include "PageMasterPropHdl.hxx"
22 #include <sax/tools/converter.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include <xmloff/xmluconv.hxx>
26 #include <xmloff/xmlnumi.hxx>
27 #include <xmloff/xmlnume.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/style/PageStyleLayout.hpp>
31 #include <comphelper/types.hxx>
32 #include <comphelper/extract.hxx>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::style;
37 using namespace ::comphelper;
38 using namespace ::xmloff::token;
40 #define DEFAULT_PAPERTRAY (sal_Int32(-1))
42 // property handler for style:page-usage (style::PageStyleLayout)
44 XMLPMPropHdl_PageStyleLayout::~XMLPMPropHdl_PageStyleLayout()
48 bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
50 style::PageStyleLayout eLayout1, eLayout2;
51 return (rAny1 >>= eLayout1) && (rAny2 >>= eLayout2) && (eLayout1 == eLayout2);
54 bool XMLPMPropHdl_PageStyleLayout::importXML(
55 const OUString& rStrImpValue,
56 Any& rValue,
57 const SvXMLUnitConverter& ) const
59 bool bRet = true;
61 if( IsXMLToken( rStrImpValue, XML_ALL ) )
62 rValue <<= PageStyleLayout_ALL;
63 else if( IsXMLToken( rStrImpValue, XML_LEFT ) )
64 rValue <<= PageStyleLayout_LEFT;
65 else if( IsXMLToken( rStrImpValue, XML_RIGHT ) )
66 rValue <<= PageStyleLayout_RIGHT;
67 else if( IsXMLToken( rStrImpValue, XML_MIRRORED ) )
68 rValue <<= PageStyleLayout_MIRRORED;
69 else
70 bRet = false;
72 return bRet;
75 bool XMLPMPropHdl_PageStyleLayout::exportXML(
76 OUString& rStrExpValue,
77 const Any& rValue,
78 const SvXMLUnitConverter& ) const
80 bool bRet = false;
81 PageStyleLayout eLayout;
83 if( rValue >>= eLayout )
85 bRet = true;
86 switch( eLayout )
88 case PageStyleLayout_ALL:
89 rStrExpValue = GetXMLToken( XML_ALL );
90 break;
91 case PageStyleLayout_LEFT:
92 rStrExpValue = GetXMLToken( XML_LEFT );
93 break;
94 case PageStyleLayout_RIGHT:
95 rStrExpValue = GetXMLToken( XML_RIGHT );
96 break;
97 case PageStyleLayout_MIRRORED:
98 rStrExpValue = GetXMLToken( XML_MIRRORED );
99 break;
100 default:
101 bRet = false;
105 return bRet;
108 // property handler for style:num-format (style::NumberingType)
110 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
114 bool XMLPMPropHdl_NumFormat::importXML(
115 const OUString& rStrImpValue,
116 Any& rValue,
117 const SvXMLUnitConverter& rUnitConverter ) const
119 sal_Int16 nSync = sal_Int16();
120 sal_Int16 nNumType = NumberingType::NUMBER_NONE;
121 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, OUString(), true );
123 if( !(rValue >>= nSync) )
124 nSync = NumberingType::NUMBER_NONE;
126 // if num-letter-sync appears before num-format, the function
127 // XMLPMPropHdl_NumLetterSync::importXML() sets the value
128 // NumberingType::CHARS_LOWER_LETTER_N
129 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
131 switch( nNumType )
133 case NumberingType::CHARS_LOWER_LETTER:
134 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
135 break;
136 case NumberingType::CHARS_UPPER_LETTER:
137 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
138 break;
141 rValue <<= nNumType;
143 return true;
146 bool XMLPMPropHdl_NumFormat::exportXML(
147 OUString& rStrExpValue,
148 const Any& rValue,
149 const SvXMLUnitConverter& rUnitConverter ) const
151 bool bRet = false;
152 sal_Int16 nNumType = sal_Int16();
154 if( rValue >>= nNumType )
156 OUStringBuffer aBuffer( 10 );
157 rUnitConverter.convertNumFormat( aBuffer, nNumType );
158 rStrExpValue = aBuffer.makeStringAndClear();
159 bRet = true;
161 return bRet;
164 // property handler for style:num-letter-sync (style::NumberingType)
166 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
170 bool XMLPMPropHdl_NumLetterSync::importXML(
171 const OUString& rStrImpValue,
172 Any& rValue,
173 const SvXMLUnitConverter& rUnitConverter ) const
175 sal_Int16 nNumType;
176 sal_Int16 nSync = NumberingType::NUMBER_NONE;
177 rUnitConverter.convertNumFormat( nSync, rStrImpValue,
178 GetXMLToken( XML_A ), true );
180 if( !(rValue >>= nNumType) )
181 nNumType = NumberingType::NUMBER_NONE;
183 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
185 switch( nNumType )
187 case NumberingType::CHARS_LOWER_LETTER:
188 nNumType = NumberingType::CHARS_LOWER_LETTER_N;
189 break;
190 case NumberingType::CHARS_UPPER_LETTER:
191 nNumType = NumberingType::CHARS_UPPER_LETTER_N;
192 break;
195 rValue <<= nNumType;
197 return true;
200 bool XMLPMPropHdl_NumLetterSync::exportXML(
201 OUString& rStrExpValue,
202 const Any& rValue,
203 const SvXMLUnitConverter& /*rUnitConverter*/ ) const
205 bool bRet = false;
206 sal_Int16 nNumType = sal_Int16();
208 if( rValue >>= nNumType )
210 OUStringBuffer aBuffer( 5 );
211 SvXMLUnitConverter::convertNumLetterSync( aBuffer, nNumType );
212 rStrExpValue = aBuffer.makeStringAndClear();
213 bRet = !rStrExpValue.isEmpty();
215 return bRet;
218 // property handler for style:paper-tray-number
220 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
224 bool XMLPMPropHdl_PaperTrayNumber::importXML(
225 const OUString& rStrImpValue,
226 Any& rValue,
227 const SvXMLUnitConverter& ) const
229 bool bRet = false;
231 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
233 rValue <<= DEFAULT_PAPERTRAY;
234 bRet = true;
236 else
238 sal_Int32 nPaperTray;
239 if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
241 rValue <<= nPaperTray;
242 bRet = true;
246 return bRet;
249 bool XMLPMPropHdl_PaperTrayNumber::exportXML(
250 OUString& rStrExpValue,
251 const Any& rValue,
252 const SvXMLUnitConverter& ) const
254 bool bRet = false;
255 sal_Int32 nPaperTray = 0;
257 if( rValue >>= nPaperTray )
259 if( nPaperTray == DEFAULT_PAPERTRAY )
260 rStrExpValue = GetXMLToken( XML_DEFAULT );
261 else
263 OUStringBuffer aBuffer;
264 ::sax::Converter::convertNumber( aBuffer, nPaperTray );
265 rStrExpValue = aBuffer.makeStringAndClear();
267 bRet = true;
269 return bRet;
272 // property handler for style:print
274 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue ) :
275 sAttrValue( GetXMLToken( eValue ) )
279 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
283 bool XMLPMPropHdl_Print::importXML(
284 const OUString& rStrImpValue,
285 Any& rValue,
286 const SvXMLUnitConverter& ) const
288 sal_Unicode cToken = ' ';
289 sal_Int32 nTokenIndex = 0;
290 bool bFound = false;
294 bFound = (sAttrValue == rStrImpValue.getToken( 0, cToken, nTokenIndex ));
296 while ( (nTokenIndex >= 0) && !bFound );
298 setBOOL( rValue, bFound );
299 return true;
302 bool XMLPMPropHdl_Print::exportXML(
303 OUString& rStrExpValue,
304 const Any& rValue,
305 const SvXMLUnitConverter& ) const
307 if( getBOOL( rValue ) )
309 if( !rStrExpValue.isEmpty() )
310 rStrExpValue += " ";
311 rStrExpValue += sAttrValue;
314 return true;
317 // property handler for style:table-centering
319 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
323 bool XMLPMPropHdl_CenterHorizontal::importXML(
324 const OUString& rStrImpValue,
325 Any& rValue,
326 const SvXMLUnitConverter& ) const
328 bool bRet = false;
330 if (!rStrImpValue.isEmpty())
331 if (IsXMLToken( rStrImpValue, XML_BOTH) ||
332 IsXMLToken( rStrImpValue, XML_HORIZONTAL))
334 rValue <<= true;
335 bRet = true;
338 return bRet;
341 bool XMLPMPropHdl_CenterHorizontal::exportXML(
342 OUString& rStrExpValue,
343 const Any& rValue,
344 const SvXMLUnitConverter& ) const
346 bool bRet = false;
348 if ( ::cppu::any2bool( rValue ) )
350 bRet = true;
351 if (!rStrExpValue.isEmpty())
352 rStrExpValue = GetXMLToken(XML_BOTH);
353 else
354 rStrExpValue = GetXMLToken(XML_HORIZONTAL);
357 return bRet;
360 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
364 bool XMLPMPropHdl_CenterVertical::importXML(
365 const OUString& rStrImpValue,
366 Any& rValue,
367 const SvXMLUnitConverter& ) const
369 bool bRet = false;
371 if (!rStrImpValue.isEmpty())
372 if (IsXMLToken(rStrImpValue, XML_BOTH) ||
373 IsXMLToken(rStrImpValue, XML_VERTICAL) )
375 rValue <<= true;
376 bRet = true;
379 return bRet;
382 bool XMLPMPropHdl_CenterVertical::exportXML(
383 OUString& rStrExpValue,
384 const Any& rValue,
385 const SvXMLUnitConverter& ) const
387 bool bRet = false;
389 if ( ::cppu::any2bool( rValue ) )
391 bRet = true;
392 if (!rStrExpValue.isEmpty())
393 rStrExpValue = GetXMLToken(XML_BOTH);
394 else
395 rStrExpValue = GetXMLToken(XML_VERTICAL);
398 return bRet;
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */