1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
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
;
82 sal_Bool
XMLPMPropHdl_PageStyleLayout::exportXML(
83 OUString
& rStrExpValue
,
85 const SvXMLUnitConverter
& ) const
87 sal_Bool bRet
= sal_False
;
88 PageStyleLayout eLayout
;
90 if( rValue
>>= eLayout
)
95 case PageStyleLayout_ALL
:
96 rStrExpValue
= GetXMLToken( XML_ALL
);
98 case PageStyleLayout_LEFT
:
99 rStrExpValue
= GetXMLToken( XML_LEFT
);
101 case PageStyleLayout_RIGHT
:
102 rStrExpValue
= GetXMLToken( XML_RIGHT
);
104 case PageStyleLayout_MIRRORED
:
105 rStrExpValue
= GetXMLToken( XML_MIRRORED
);
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
,
126 const SvXMLUnitConverter
& rUnitConverter
) const
128 sal_Int16 nSync
= sal_Int16();
129 sal_Int16 nNumType
= NumberingType::NUMBER_NONE
;
130 rUnitConverter
.convertNumFormat( nNumType
, rStrImpValue
, OUString(),
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
)
143 case NumberingType::CHARS_LOWER_LETTER
:
144 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
146 case NumberingType::CHARS_UPPER_LETTER
:
147 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
156 sal_Bool
XMLPMPropHdl_NumFormat::exportXML(
157 OUString
& rStrExpValue
,
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();
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
,
185 const SvXMLUnitConverter
& rUnitConverter
) const
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
)
199 case NumberingType::CHARS_LOWER_LETTER
:
200 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
202 case NumberingType::CHARS_UPPER_LETTER
:
203 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
212 sal_Bool
XMLPMPropHdl_NumLetterSync::exportXML(
213 OUString
& rStrExpValue
,
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();
231 //______________________________________________________________________________
232 // property handler for style:paper-tray-number
234 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
238 sal_Bool
XMLPMPropHdl_PaperTrayNumber::importXML(
239 const OUString
& rStrImpValue
,
241 const SvXMLUnitConverter
& ) const
243 sal_Bool bRet
= sal_False
;
245 if( IsXMLToken( rStrImpValue
, XML_DEFAULT
) )
247 rValue
<<= DEFAULT_PAPERTRAY
;
252 sal_Int32 nPaperTray
;
253 if (::sax::Converter::convertNumber( nPaperTray
, rStrImpValue
, 0 ))
255 rValue
<<= nPaperTray
;
263 sal_Bool
XMLPMPropHdl_PaperTrayNumber::exportXML(
264 OUString
& rStrExpValue
,
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
);
277 OUStringBuffer aBuffer
;
278 ::sax::Converter::convertNumber( aBuffer
, nPaperTray
);
279 rStrExpValue
= aBuffer
.makeStringAndClear();
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
,
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
);
318 sal_Bool
XMLPMPropHdl_Print::exportXML(
319 OUString
& rStrExpValue
,
321 const SvXMLUnitConverter
& ) const
323 if( getBOOL( rValue
) )
325 if( !rStrExpValue
.isEmpty() )
327 rStrExpValue
+= sAttrValue
;
333 //______________________________________________________________________________
334 // property handler for style:table-centering
336 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
340 sal_Bool
XMLPMPropHdl_CenterHorizontal::importXML(
341 const OUString
& rStrImpValue
,
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
);
359 sal_Bool
XMLPMPropHdl_CenterHorizontal::exportXML(
360 OUString
& rStrExpValue
,
362 const SvXMLUnitConverter
& ) const
364 sal_Bool bRet
= sal_False
;
366 if ( ::cppu::any2bool( rValue
) )
369 if (!rStrExpValue
.isEmpty())
370 rStrExpValue
= GetXMLToken(XML_BOTH
);
372 rStrExpValue
= GetXMLToken(XML_HORIZONTAL
);
378 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
382 sal_Bool
XMLPMPropHdl_CenterVertical::importXML(
383 const OUString
& rStrImpValue
,
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
);
400 sal_Bool
XMLPMPropHdl_CenterVertical::exportXML(
401 OUString
& rStrExpValue
,
403 const SvXMLUnitConverter
& ) const
405 sal_Bool bRet
= sal_False
;
407 if ( ::cppu::any2bool( rValue
) )
410 if (!rStrExpValue
.isEmpty())
411 rStrExpValue
= GetXMLToken(XML_BOTH
);
413 rStrExpValue
= GetXMLToken(XML_VERTICAL
);
419 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */