LibreOffice Module xmloff (master) 1
PageMasterPropHdl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "PageMasterPropHdl.hxx"
21
23
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>
32#include <o3tl/string_view.hxx>
33
34using namespace ::com::sun::star;
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::style;
37using namespace ::comphelper;
38using namespace ::xmloff::token;
39
40#define DEFAULT_PAPERTRAY (sal_Int32(-1))
41
42// property handler for style:page-usage (style::PageStyleLayout)
43
45{
46}
47
48bool XMLPMPropHdl_PageStyleLayout::equals( const Any& rAny1, const Any& rAny2 ) const
49{
50 style::PageStyleLayout eLayout1, eLayout2;
51 return (rAny1 >>= eLayout1) && (rAny2 >>= eLayout2) && (eLayout1 == eLayout2);
52}
53
55 const OUString& rStrImpValue,
56 Any& rValue,
57 const SvXMLUnitConverter& ) const
58{
59 bool bRet = true;
60
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;
71
72 return bRet;
73}
74
76 OUString& rStrExpValue,
77 const Any& rValue,
78 const SvXMLUnitConverter& ) const
79{
80 bool bRet = false;
81 PageStyleLayout eLayout;
82
83 if( rValue >>= eLayout )
84 {
85 bRet = true;
86 switch( eLayout )
87 {
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;
102 }
103 }
104
105 return bRet;
106}
107
108// property handler for style:num-format (style::NumberingType)
109
111{
112}
113
115 const OUString& rStrImpValue,
116 Any& rValue,
117 const SvXMLUnitConverter& rUnitConverter ) const
118{
119 sal_Int16 nSync = sal_Int16();
120 sal_Int16 nNumType = NumberingType::NUMBER_NONE;
121 rUnitConverter.convertNumFormat( nNumType, rStrImpValue, u"", true );
122
123 if( !(rValue >>= nSync) )
124 nSync = NumberingType::NUMBER_NONE;
125
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 )
130 {
131 switch( nNumType )
132 {
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;
139 }
140 }
141 rValue <<= nNumType;
142
143 return true;
144}
145
147 OUString& rStrExpValue,
148 const Any& rValue,
149 const SvXMLUnitConverter& rUnitConverter ) const
150{
151 bool bRet = false;
152 sal_Int16 nNumType = sal_Int16();
153
154 if( rValue >>= nNumType )
155 {
156 OUStringBuffer aBuffer( 10 );
157 rUnitConverter.convertNumFormat( aBuffer, nNumType );
158 rStrExpValue = aBuffer.makeStringAndClear();
159 bRet = true;
160 }
161 return bRet;
162}
163
164// property handler for style:num-letter-sync (style::NumberingType)
165
167{
168}
169
171 const OUString& rStrImpValue,
172 Any& rValue,
173 const SvXMLUnitConverter& rUnitConverter ) const
174{
175 sal_Int16 nNumType;
176 sal_Int16 nSync = NumberingType::NUMBER_NONE;
177 rUnitConverter.convertNumFormat( nSync, rStrImpValue,
178 GetXMLToken( XML_A ), true );
179
180 if( !(rValue >>= nNumType) )
181 nNumType = NumberingType::NUMBER_NONE;
182
183 if( nSync == NumberingType::CHARS_LOWER_LETTER_N )
184 {
185 switch( nNumType )
186 {
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;
193 }
194 }
195 rValue <<= nNumType;
196
197 return true;
198}
199
201 OUString& rStrExpValue,
202 const Any& rValue,
203 const SvXMLUnitConverter& /*rUnitConverter*/ ) const
204{
205 bool bRet = false;
206 sal_Int16 nNumType = sal_Int16();
207
208 if( rValue >>= nNumType )
209 {
210 OUStringBuffer aBuffer( 5 );
212 rStrExpValue = aBuffer.makeStringAndClear();
213 bRet = !rStrExpValue.isEmpty();
214 }
215 return bRet;
216}
217
218// property handler for style:paper-tray-number
219
221{
222}
223
225 const OUString& rStrImpValue,
226 Any& rValue,
227 const SvXMLUnitConverter& ) const
228{
229 bool bRet = false;
230
231 if( IsXMLToken( rStrImpValue, XML_DEFAULT ) )
232 {
233 rValue <<= DEFAULT_PAPERTRAY;
234 bRet = true;
235 }
236 else
237 {
238 sal_Int32 nPaperTray;
239 if (::sax::Converter::convertNumber( nPaperTray, rStrImpValue, 0 ))
240 {
241 rValue <<= nPaperTray;
242 bRet = true;
243 }
244 }
245
246 return bRet;
247}
248
250 OUString& rStrExpValue,
251 const Any& rValue,
252 const SvXMLUnitConverter& ) const
253{
254 bool bRet = false;
255 sal_Int32 nPaperTray = 0;
256
257 if( rValue >>= nPaperTray )
258 {
259 if( nPaperTray == DEFAULT_PAPERTRAY )
260 rStrExpValue = GetXMLToken( XML_DEFAULT );
261 else
262 {
263 rStrExpValue = OUString::number( nPaperTray );
264 }
265 bRet = true;
266 }
267 return bRet;
268}
269
270// property handler for style:print
271
273 sAttrValue( GetXMLToken( eValue ) )
274{
275}
276
278{
279}
280
282 const OUString& rStrImpValue,
283 Any& rValue,
284 const SvXMLUnitConverter& ) const
285{
286 sal_Int32 nTokenIndex = 0;
287 bool bFound = false;
288
289 do
290 {
291 bFound = (sAttrValue == o3tl::getToken(rStrImpValue, 0, ' ', nTokenIndex ));
292 }
293 while ( (nTokenIndex >= 0) && !bFound );
294
295 rValue <<= bFound;
296 return true;
297}
298
300 OUString& rStrExpValue,
301 const Any& rValue,
302 const SvXMLUnitConverter& ) const
303{
304 if( getBOOL( rValue ) )
305 {
306 if( !rStrExpValue.isEmpty() )
307 rStrExpValue += " ";
308 rStrExpValue += sAttrValue;
309 }
310
311 return true;
312}
313
314// property handler for style:table-centering
315
317{
318}
319
321 const OUString& rStrImpValue,
322 Any& rValue,
323 const SvXMLUnitConverter& ) const
324{
325 bool bRet = false;
326
327 if (!rStrImpValue.isEmpty())
328 if (IsXMLToken( rStrImpValue, XML_BOTH) ||
329 IsXMLToken( rStrImpValue, XML_HORIZONTAL))
330 {
331 rValue <<= true;
332 bRet = true;
333 }
334
335 return bRet;
336}
337
339 OUString& rStrExpValue,
340 const Any& rValue,
341 const SvXMLUnitConverter& ) const
342{
343 bool bRet = false;
344
345 if ( ::cppu::any2bool( rValue ) )
346 {
347 bRet = true;
348 if (!rStrExpValue.isEmpty())
349 rStrExpValue = GetXMLToken(XML_BOTH);
350 else
351 rStrExpValue = GetXMLToken(XML_HORIZONTAL);
352 }
353
354 return bRet;
355}
356
358{
359}
360
362 const OUString& rStrImpValue,
363 Any& rValue,
364 const SvXMLUnitConverter& ) const
365{
366 bool bRet = false;
367
368 if (!rStrImpValue.isEmpty())
369 if (IsXMLToken(rStrImpValue, XML_BOTH) ||
370 IsXMLToken(rStrImpValue, XML_VERTICAL) )
371 {
372 rValue <<= true;
373 bRet = true;
374 }
375
376 return bRet;
377}
378
380 OUString& rStrExpValue,
381 const Any& rValue,
382 const SvXMLUnitConverter& ) const
383{
384 bool bRet = false;
385
386 if ( ::cppu::any2bool( rValue ) )
387 {
388 bRet = true;
389 if (!rStrExpValue.isEmpty())
390 rStrExpValue = GetXMLToken(XML_BOTH);
391 else
392 rStrExpValue = GetXMLToken(XML_VERTICAL);
393 }
394
395 return bRet;
396}
397
398/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DEFAULT_PAPERTRAY
the SvXMLTypeConverter converts values of various types from their internal representation to the tex...
Definition: xmluconv.hxx:83
bool convertNumFormat(sal_Int16 &rType, const OUString &rNumFormat, std::u16string_view rNumLetterSync, bool bNumberNone=false) const
convert num-format and num-letter-sync values to NumberingType
Definition: xmluconv.cxx:655
static void convertNumLetterSync(OUStringBuffer &rBuffer, sal_Int16 nType)
Definition: xmluconv.cxx:752
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_CenterHorizontal() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_CenterVertical() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_NumFormat() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_NumLetterSync() override
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual bool equals(const css::uno::Any &rAny1, const css::uno::Any &rAny2) const override
Compares two Any's in case of the given XML-data-type.
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_PageStyleLayout() override
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_PaperTrayNumber() override
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
virtual ~XMLPMPropHdl_Print() override
virtual bool importXML(const OUString &rStrImpValue, css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Imports the given value according to the XML-data-type corresponding to the derived class.
XMLPMPropHdl_Print(enum ::xmloff::token::XMLTokenEnum eValue)
virtual bool exportXML(OUString &rStrExpValue, const css::uno::Any &rValue, const SvXMLUnitConverter &rUnitConverter) const override
Exports the given value according to the XML-data-type corresponding to the derived class.
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
float u
sal_Int16 nNumType
bool getBOOL(const Any &_rAny)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
Definition: xmltoken.cxx:3597
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
std::unique_ptr< char[]> aBuffer