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 <rtl/ustrbuf.hxx>
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/style/PageStyleLayout.hpp>
29 #include <com/sun/star/style/NumberingType.hpp>
30 #include <comphelper/types.hxx>
31 #include <comphelper/extract.hxx>
32 #include <o3tl/string_view.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
, u
"", 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 rStrExpValue
= OUString::number( nPaperTray
);
270 // property handler for style:print
272 XMLPMPropHdl_Print::XMLPMPropHdl_Print( enum XMLTokenEnum eValue
) :
273 sAttrValue( GetXMLToken( eValue
) )
277 XMLPMPropHdl_Print::~XMLPMPropHdl_Print()
281 bool XMLPMPropHdl_Print::importXML(
282 const OUString
& rStrImpValue
,
284 const SvXMLUnitConverter
& ) const
286 sal_Int32 nTokenIndex
= 0;
291 bFound
= (sAttrValue
== o3tl::getToken(rStrImpValue
, 0, ' ', nTokenIndex
));
293 while ( (nTokenIndex
>= 0) && !bFound
);
299 bool XMLPMPropHdl_Print::exportXML(
300 OUString
& rStrExpValue
,
302 const SvXMLUnitConverter
& ) const
304 if( getBOOL( rValue
) )
306 if( !rStrExpValue
.isEmpty() )
308 rStrExpValue
+= sAttrValue
;
314 // property handler for style:table-centering
316 XMLPMPropHdl_CenterHorizontal::~XMLPMPropHdl_CenterHorizontal()
320 bool XMLPMPropHdl_CenterHorizontal::importXML(
321 const OUString
& rStrImpValue
,
323 const SvXMLUnitConverter
& ) const
327 if (!rStrImpValue
.isEmpty())
328 if (IsXMLToken( rStrImpValue
, XML_BOTH
) ||
329 IsXMLToken( rStrImpValue
, XML_HORIZONTAL
))
338 bool XMLPMPropHdl_CenterHorizontal::exportXML(
339 OUString
& rStrExpValue
,
341 const SvXMLUnitConverter
& ) const
345 if ( ::cppu::any2bool( rValue
) )
348 if (!rStrExpValue
.isEmpty())
349 rStrExpValue
= GetXMLToken(XML_BOTH
);
351 rStrExpValue
= GetXMLToken(XML_HORIZONTAL
);
357 XMLPMPropHdl_CenterVertical::~XMLPMPropHdl_CenterVertical()
361 bool XMLPMPropHdl_CenterVertical::importXML(
362 const OUString
& rStrImpValue
,
364 const SvXMLUnitConverter
& ) const
368 if (!rStrImpValue
.isEmpty())
369 if (IsXMLToken(rStrImpValue
, XML_BOTH
) ||
370 IsXMLToken(rStrImpValue
, XML_VERTICAL
) )
379 bool XMLPMPropHdl_CenterVertical::exportXML(
380 OUString
& rStrExpValue
,
382 const SvXMLUnitConverter
& ) const
386 if ( ::cppu::any2bool( rValue
) )
389 if (!rStrExpValue
.isEmpty())
390 rStrExpValue
= GetXMLToken(XML_BOTH
);
392 rStrExpValue
= GetXMLToken(XML_VERTICAL
);
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */