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 .
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
,
57 const SvXMLUnitConverter
& ) const
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
;
75 bool XMLPMPropHdl_PageStyleLayout::exportXML(
76 OUString
& rStrExpValue
,
78 const SvXMLUnitConverter
& ) const
81 PageStyleLayout eLayout
;
83 if( rValue
>>= eLayout
)
88 case PageStyleLayout_ALL
:
89 rStrExpValue
= GetXMLToken( XML_ALL
);
91 case PageStyleLayout_LEFT
:
92 rStrExpValue
= GetXMLToken( XML_LEFT
);
94 case PageStyleLayout_RIGHT
:
95 rStrExpValue
= GetXMLToken( XML_RIGHT
);
97 case PageStyleLayout_MIRRORED
:
98 rStrExpValue
= GetXMLToken( XML_MIRRORED
);
108 // property handler for style:num-format (style::NumberingType)
110 XMLPMPropHdl_NumFormat::~XMLPMPropHdl_NumFormat()
114 bool XMLPMPropHdl_NumFormat::importXML(
115 const OUString
& rStrImpValue
,
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
)
133 case NumberingType::CHARS_LOWER_LETTER
:
134 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
136 case NumberingType::CHARS_UPPER_LETTER
:
137 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
146 bool XMLPMPropHdl_NumFormat::exportXML(
147 OUString
& rStrExpValue
,
149 const SvXMLUnitConverter
& rUnitConverter
) const
152 sal_Int16 nNumType
= sal_Int16();
154 if( rValue
>>= nNumType
)
156 OUStringBuffer
aBuffer( 10 );
157 rUnitConverter
.convertNumFormat( aBuffer
, nNumType
);
158 rStrExpValue
= aBuffer
.makeStringAndClear();
164 // property handler for style:num-letter-sync (style::NumberingType)
166 XMLPMPropHdl_NumLetterSync::~XMLPMPropHdl_NumLetterSync()
170 bool XMLPMPropHdl_NumLetterSync::importXML(
171 const OUString
& rStrImpValue
,
173 const SvXMLUnitConverter
& rUnitConverter
) const
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
)
187 case NumberingType::CHARS_LOWER_LETTER
:
188 nNumType
= NumberingType::CHARS_LOWER_LETTER_N
;
190 case NumberingType::CHARS_UPPER_LETTER
:
191 nNumType
= NumberingType::CHARS_UPPER_LETTER_N
;
200 bool XMLPMPropHdl_NumLetterSync::exportXML(
201 OUString
& rStrExpValue
,
203 const SvXMLUnitConverter
& /*rUnitConverter*/ ) const
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();
218 // property handler for style:paper-tray-number
220 XMLPMPropHdl_PaperTrayNumber::~XMLPMPropHdl_PaperTrayNumber()
224 bool XMLPMPropHdl_PaperTrayNumber::importXML(
225 const OUString
& rStrImpValue
,
227 const SvXMLUnitConverter
& ) const
231 if( IsXMLToken( rStrImpValue
, XML_DEFAULT
) )
233 rValue
<<= DEFAULT_PAPERTRAY
;
238 sal_Int32 nPaperTray
;
239 if (::sax::Converter::convertNumber( nPaperTray
, rStrImpValue
, 0 ))
241 rValue
<<= nPaperTray
;
249 bool XMLPMPropHdl_PaperTrayNumber::exportXML(
250 OUString
& rStrExpValue
,
252 const SvXMLUnitConverter
& ) const
255 sal_Int32 nPaperTray
= 0;
257 if( rValue
>>= nPaperTray
)
259 if( nPaperTray
== DEFAULT_PAPERTRAY
)
260 rStrExpValue
= GetXMLToken( XML_DEFAULT
);
263 OUStringBuffer aBuffer
;
264 ::sax::Converter::convertNumber( aBuffer
, nPaperTray
);
265 rStrExpValue
= aBuffer
.makeStringAndClear();
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
,
286 const SvXMLUnitConverter
& ) const
288 sal_Unicode cToken
= ' ';
289 sal_Int32 nTokenIndex
= 0;
294 bFound
= (sAttrValue
== rStrImpValue
.getToken( 0, cToken
, nTokenIndex
));
296 while ( (nTokenIndex
>= 0) && !bFound
);
298 setBOOL( rValue
, bFound
);
302 bool XMLPMPropHdl_Print::exportXML(
303 OUString
& rStrExpValue
,
305 const SvXMLUnitConverter
& ) const
307 if( getBOOL( rValue
) )
309 if( !rStrExpValue
.isEmpty() )
311 rStrExpValue
+= sAttrValue
;
317 // property handler for style:table-centering
319 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
323 bool XMLPMPropHdl_CenterHorizontal::importXML(
324 const OUString
& rStrImpValue
,
326 const SvXMLUnitConverter
& ) const
330 if (!rStrImpValue
.isEmpty())
331 if (IsXMLToken( rStrImpValue
, XML_BOTH
) ||
332 IsXMLToken( rStrImpValue
, XML_HORIZONTAL
))
341 bool XMLPMPropHdl_CenterHorizontal::exportXML(
342 OUString
& rStrExpValue
,
344 const SvXMLUnitConverter
& ) const
348 if ( ::cppu::any2bool( rValue
) )
351 if (!rStrExpValue
.isEmpty())
352 rStrExpValue
= GetXMLToken(XML_BOTH
);
354 rStrExpValue
= GetXMLToken(XML_HORIZONTAL
);
360 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
364 bool XMLPMPropHdl_CenterVertical::importXML(
365 const OUString
& rStrImpValue
,
367 const SvXMLUnitConverter
& ) const
371 if (!rStrImpValue
.isEmpty())
372 if (IsXMLToken(rStrImpValue
, XML_BOTH
) ||
373 IsXMLToken(rStrImpValue
, XML_VERTICAL
) )
382 bool XMLPMPropHdl_CenterVertical::exportXML(
383 OUString
& rStrExpValue
,
385 const SvXMLUnitConverter
& ) const
389 if ( ::cppu::any2bool( rValue
) )
392 if (!rStrExpValue
.isEmpty())
393 rStrExpValue
= GetXMLToken(XML_BOTH
);
395 rStrExpValue
= GetXMLToken(XML_VERTICAL
);
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */